Skip to content

Fix llama.cpp's --no-mmap Invalid Argument Error

If llama.cpp reports error: invalid argument: --no-mmap, check the help for the executable that rejected it. When its help lists --load-mode, use --load-mode none to keep memory mapping disabled. If you copied the old flag from a tutorial and have no reason to disable mapping, leave the loading option out and use the binary's default.

1. Identify the llama.cpp executable and its options

Run --version and --help against the same executable that printed the error. These commands assume you run the CLI from a source checkout. If you launch it from your shell's PATH, type -a llama-cli shows the commands your shell can find.

./build/bin/llama-cli --version
./build/bin/llama-cli --help 2>&1 | grep -E -- 'load-mode|no-mmap|mmap|mlock'

Use ./build/bin/llama-server for the server. If there is no matching output, run the full help command to see whether the executable could start. An installed package, container, or service can point to a different build from the one in your project directory.

What the executable's help shows What to pass
--load-mode and the none mode Use --load-mode none to preserve the unmapped loading behaviour. Remove the old --no-mmap flag from the command.
--no-mmap on an older build Use --no-mmap if you need it on that build.
You want the normal loading behaviour Omit the loading flag and check for any loader environment setting in your launcher. On the tested build the default is auto.

For the tested parser, none selects the ordinary read path without model memory mapping or locking. It still loads the model. mlock and mmap+mlock request memory locking, so choose them only when locking is your goal. llama.cpp parser at the tested revision

2. Confirm that the replacement loads a GGUF

Run a small model you already know works. This example uses the file from the llama.cpp setup guide. Run it from that guide's checkout and use a build whose help lists --load-mode none.

1
2
3
4
./build/bin/llama-cli \
  -m models/SmolLM2-135M-Instruct-Q4_K_M.gguf \
  --device none --single-turn --load-mode none --verbose \
  -p "Write one short sentence about a garden." -n 12 -t 2 -c 512

On a Pi 4B with llama.cpp commit cbb1c1c, the old flag exited with code 1 and printed the invalid-argument error. The command above completed and the final load_tensors line showed load_mode = none. Repeating it with --load-mode mmap completed with load_mode = mmap on that line. Check the loader's reported mode when comparing runs.

An error about opening the GGUF or allocating memory is a later failure. Check the path, choose a smaller model or context as needed, and read the memory and OOM diagnostics.

3. Check the launcher if the old flag keeps appearing

  • For a shell script or systemd service, inspect the actual launch command. For a unit called llama.service, run systemctl cat llama.service and check ExecStart= and any referenced script. Use your own unit name.
  • For Docker Compose, check the service's command and the image's entrypoint. Run help against the executable inside the image before updating the flags.
  • If your launcher sets LLAMA_ARG_LOAD_MODE, check that it agrees with your intended mode and remove any rejected flag from the command. The tested native parser accepts this variable.
  • If your project calls llama_cpp.Llama from llama-cpp-python, the constructor exposes use_mmap=False. Check the interface of the Python package you installed. llama-cpp-python API reference
Donate