Skip to content

Rust library

Beyond the CLI, dlm is a Rust crate. Depend on it to drive the engine directly — profile, load, generate, or route a forward pass across nodes.

Add the dependency

$cargo install --git https://github.com/vedantnimbarte/dlm
$cargo add --git https://github.com/vedantnimbarte/dlm dlm
GPU code is behind the cuda, cuda-kernels, and rocm features — enable the one that matches your target. See Build & features.

Key modules

ModuleWhat's inside
forwardThe ComputeKernel trait (run_block), the ForwardOrchestrator, and the CPU / GPU / streaming kernels.
profilerThe VRAM plan — the LayersToLoad budget math.
loaderReads HF-named safetensors (F32/F16/BF16, or 4-bit GPTQ/AWQ) and GGUF files into the transformer, embedding, and LM head.
generateThe end-to-end token → logits → sample loop.
distributedpartition_layers, the Coordinator, and the worker protocol.
serverThe OpenAI-compatible HTTP engine and batching service.

Example: distributed coordinator

Split a model across worker nodes and route generation through them — the result equals a local greedy run and survives a dead worker.

$ rust
  use dlm::distributed::{partition_layers, Coordinator};

  let shards = partition_layers(num_layers, 2);
  let mut coord = Coordinator::new(
      cfg, layers, embed, norm, head, vocab, routes)?;
  let tokens = coord.generate(&prompt, 32)?;

The ComputeKernel trait

The transformer math sits behind a block-level trait — run_block runs one decoder block for one token. Implement it to swap in your own compute path; the orchestrator drives it autoregressively. See Architecture & math for the CPU / Stub / GPU kernels behind it.

Source

The crate is the source of truth for every API — browse it on GitHub, and read the module docs inline with cargo doc --open.