Tutorials

How to Run NVIDIA Dory 4B Locally

Step-by-step tutorial on running NVIDIA Dory 4B locally using llama.cpp with complete code and troubleshooting.

AM
Alfian Majid
//6 min read
How to Run NVIDIA Dory 4B Locally

Why Local Weights Matter When Grid Power Falters

The grid in Texas is wobbling under the immense weight of speculative data center buildouts, forcing engineering teams to rethink where inference actually lives. If massive regional clusters face curtailments and rising power tariffs, relying entirely on remote cloud endpoints becomes an expensive operational hazard. Running compact, highly efficient models locally on consumer or edge hardware is no longer just a privacy play. It is a necessary resilience strategy for production pipelines that cannot afford cloud downtime or sudden API pricing spikes.

NVIDIA Dory 4B represents a shift toward dense, high-performance edge inference that fits comfortably on consumer-grade silicon. When paired with llama.cpp, you bypass the massive memory overhead of standard PyTorch runtimes and execute GGUF-quantized weights directly on your metal. Throughout this tutorial, we will configure, compile, and run Dory 4B locally, optimizing every loop for maximum tokens per second without melting your local cooling fans.

Hardware Prerequisites and Environment Specifications

Before touching any code, let us align on the exact hardware footprint required to keep this model running smoothly. You need a system equipped with at least 16GB of unified memory or a dedicated GPU with 12GB of VRAM to comfortably load the 4-bit quantized version of Dory 4B alongside context buffers. Anything less will trigger severe swap thrashing and tank your inference speed.

We will build from source using CMake version 3.25 or higher and a modern C++ compiler supporting C++17. Open your terminal and verify your toolchain versions before proceeding with the installation steps:

cmake --version
gcc --version
python3 --version

If your compiler defaults are older than GCC 11 or Clang 14, update your build essentials immediately. Mismatched compiler versions will cause silent vectorization failures during the compilation of hardware-accelerated kernels in llama.cpp.

Compiling llama.cpp with CUDA or Metal Acceleration

We need to build llama.cpp from source to ensure hardware-specific acceleration flags are fully engaged. Clone the upstream repository and check out a stable commit known to handle custom model architectures cleanly. Run the following shell commands to pull the source tree and initialize your build directory:

git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
cmake -B build -DGGML_CUDA=ON
cmake --build build --config Release

If you are developing on Apple Silicon rather than an NVIDIA rig, swap out the CMake flag to target Metal acceleration instead of CUDA:

cmake -B build -DGGML_METAL=ON
cmake --build build --config Release

Verify that your build artifacts compiled correctly by checking the binary output in the build folder. You should see llama-cli and llama-server compiled and ready for execution.

Downloading and Converting Dory 4B Weights

Fetching the raw model files requires access to the appropriate Hugging Face repositories where the Dory 4B release is hosted. Ensure you have the Hugging Face CLI installed and authenticated with your user token before downloading the safetensors archive:

pip install huggingface_hub
huggingface-cli login
huggingface-cli download nvidia/dory-4b --local-dir ./models/dory-4b

Once the raw weights are stored locally, convert them into the GGUF format required by our compiled llama.cpp runtime. Execute the conversion python script included in the repository, specifying q4_K_M as your quantization target for the optimal balance between perplexity retention and memory footprint:

python3 convert_hf_to_gguf.py ./models/dory-4b --outtype q4_K_M --outfile ./models/dory-4b-q4_K_M.gguf

This quantization step compresses the model parameters down to roughly 4.5 bits per weight, shrinking the total file size from its bulky floating-point origins to something that loads into memory in under two seconds.

Executing Your First Local Inference Loop

With the GGUF binary ready in your models directory, we can spin up an interactive inference session. We will use the llama-cli binary with specific parameter flags to control context length, thread allocation, and prompt caching. Enter this command into your terminal to launch the model:

./build/bin/llama-cli \
  -m ./models/dory-4b-q4_K_M.gguf \
  -p "Explain the thermodynamic limits of edge data centers." \
  -n 512 \
  -t 8 \
  --temp 0.7 \
  --ctx-size 4096

Watch the terminal output closely as the context initializes. You should see token generation begin almost immediately if your hardware acceleration flags compiled correctly. Pay attention to the performance metrics printed at the bottom of the generation stream, noting your prompt processing speed and token generation rate.

How Do You Diagnose and Fix Common Quantization Errors?

Local inference setups rarely work on the first try due to version mismatches and hardware quirks. When your build fails with segmentation faults or memory allocation errors, you need a systematic troubleshooting playbook to isolate the root cause.

The most frequent issue involves running out of VRAM, which causes the runtime to silently offload layers back to system RAM, destroying your performance. Look out for these three common error messages and apply the corresponding fix immediately:

    GGML_ASSERT: tensor size mismatch: This occurs when your convert_hf_to_gguf.py script is out of sync with your llama.cpp binary. Pull the latest commits on both repositories and re-run the conversion pipeline from scratch. CUDA out of memory (OOM): Reduce your context window parameter using the --ctx-size 2048 flag, or offload fewer layers to the GPU by adjusting the -ngl parameter down from its maximum default value. Illegal instruction (core dumped): Your compiled binary is using AVX-512 instructions that your specific CPU model does not support. Rebuild the project without advanced vector extensions by passing -DGGML_NATIVE=OFF to CMake.

Production Considerations for Edge Deployments

Moving a local model from a developer workstation to a production edge node requires locking down your runtime environment against resource starvation and concurrency bottlenecks. Never expose raw llama.cpp binaries directly to the public internet without an API gateway managing request queues and rate limits.

Instead of the CLI binary, spin up the built-in HTTP server wrapper to expose an OpenAI-compatible endpoint for your internal microservices:

./build/bin/llama-server \
  -m ./models/dory-4b-q4_K_M.gguf \
  --port 8080 \
  --host 127.0.0.1 \
  -np 4 \
  -cb

The -np 4 flag enables parallel slot management, allowing the server to batch incoming requests efficiently. Monitor your host memory consumption using system metrics tools like htop or nvidia-smi to ensure thermal throttling does not kick in during sustained inference loads.

What to Build Next with Local Weights

Once you have Dory 4B running reliably on your local hardware, you can expand your architecture into more complex agentic workflows without relying on external cloud APIs. Combine this local inference engine with lightweight vector databases like Qdrant to build an air-gapped retrieval-augmented generation pipeline that runs entirely offline.

You can also hook the local server endpoint into agent frameworks like LangGraph or custom Python scripts using the standard OpenAI client library by simply overriding the base_url parameter. This setup gives you complete control over your data lifecycle, shielding your applications from both cloud outages and regional grid instability.

Bottom Line

Relying exclusively on hyperscale cloud infrastructure for every token generation task is an unnecessary fragility in modern software engineering. Take the time to build and run models like NVIDIA Dory 4B locally on your own hardware using optimized runtimes. It keeps your latency predictable, your operational costs fixed, and your data entirely under your control when external systems fail.

Share this article

Alfian Majid
Alfian Majid/Founder & Editor-in-Chief

Solo developer and blogger from Indonesia. Runs CogitoDaily as a passion project - covering AI news, testing tools, and writing guides. Background in web development and game tech. When not writing about AI, you'll find me deep in anime or gaming.