# Inference The Olmicro models are base models: they continue text, they do not follow chat instructions, and they ship no chat template. Every branch of every model repo is a complete transformers checkpoint (bf16 weights, config, tokenizer and modeling code), so the same code runs the final model (`main`) and any intermediate checkpoint (`stage-step<7 digits>`, listed in the model repo's branches). | Path | Needs | Script | |---|---|---| | transformers | transformers >= 5.12, < 5.16, `trust_remote_code=True` | [`scripts/inference/hf_generate.py`](../scripts/inference/hf_generate.py) | | vLLM | vLLM + [`plugins/vllm_plugin`](../plugins/vllm_plugin) + [`plugins/transformers_plugin`](../plugins/transformers_plugin) | [`scripts/inference/vllm_generate.py`](../scripts/inference/vllm_generate.py) | | Olmo-core checkpoint -> transformers | this repo's environment | [`scripts/convert/convert_olmo_core_to_hf.py`](../scripts/convert/convert_olmo_core_to_hf.py) | Tested: transformers 5.12.1 and 5.15.1, vLLM 0.25.1 (this repo's environment plus the vLLM plugin, torch 2.11) and 0.19.1 (olmo-eval's environment), on A100 and B300 GPUs. ## transformers ```python import torch from transformers import AutoModelForCausalLM, AutoTokenizer repo, revision = "allenai/olmicro-1.4b-base", "main" # or e.g. "stage1-step0100000" tokenizer = AutoTokenizer.from_pretrained(repo, revision=revision, trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained(repo, revision=revision, trust_remote_code=True, dtype=torch.bfloat16).to("cuda") inputs = tokenizer("The capital of France is", return_tensors="pt").to(model.device) out = model.generate(**inputs, max_new_tokens=32, do_sample=False) print(tokenizer.decode(out[0], skip_special_tokens=True)) ``` - **`trust_remote_code=True`** loads the modeling code stored in the branch (`configuration_olmicro.py`, `modeling_olmicro.py`, identical in every branch). Pass it to `AutoTokenizer` too: without it, transformers asks interactively whether to run the custom code before falling back to the tokenizer. - **Without remote code**: install [`plugins/transformers_plugin`](../plugins/transformers_plugin) (part of `uv sync` here) and call `transformers_plugin.register()` before `from_pretrained`; it registers the same classes with the `Auto*` classes. `hf_generate.py --use-plugin` does this. - **Kernels.** With [flash-linear-attention](https://github.com/fla-org/flash-linear-attention) installed (it is in this repo's environment), the Gated DeltaNet layers use its Triton kernels; without it they fall back to a slow pure-PyTorch implementation (with a warning at load time). The first forward pass compiles and autotunes the Triton kernels, which takes a few minutes on a new GPU; later runs use Triton's cache. - **Precision.** The weights are stored in bf16, the dtype the evals ran in; `dtype=torch.float32` also works. - **Intermediate checkpoints.** List a repo's branches with `huggingface_hub.list_repo_refs("allenai/olmicro-275m-base").branches`. ```bash uv run scripts/inference/hf_generate.py allenai/olmicro-275m-base "The capital of France is" uv run scripts/inference/hf_generate.py allenai/olmicro-1.4b-base "def fib(n):" --revision stage1-step0100000 ``` ## vLLM The `olmicro` architecture is not in vLLM yet. [`plugins/vllm_plugin`](../plugins/vllm_plugin) is a [vLLM general plugin](https://docs.vllm.ai/en/latest/design/plugin_system.html): once installed, vLLM loads it in every process at startup and it registers the architecture (and, through `transformers_plugin`, the config). Nothing needs to be imported or called. The plugin is a standalone package, not part of `uv sync`. It declares vLLM 0.25 (the vLLM line built on torch 2.11) and needs `transformers_plugin`, which `uv sync` installs: ```bash uv sync # this repo's environment, with transformers_plugin uv pip install --python .venv/bin/python ./plugins/vllm_plugin # + vLLM 0.25 and the vLLM plugin (a later plain `uv sync` removes them) # or, into another environment (install both plugins at the same ref; add --no-deps to keep a vLLM already installed): pip install "olmicro-vllm-plugin @ git+https://github.com/allenai/olmicro.git@main#subdirectory=plugins/vllm_plugin" \ "olmicro-transformers-plugin @ git+https://github.com/allenai/olmicro.git@main#subdirectory=plugins/transformers_plugin" ``` ```python from vllm import LLM, SamplingParams llm = LLM("allenai/olmicro-1.4b-base", revision="main", tokenizer_revision="main", dtype="bfloat16", mamba_ssm_cache_dtype="float32") out = llm.generate(["The capital of France is"], SamplingParams(temperature=0, max_tokens=32)) print(out[0].outputs[0].text) ``` ```bash uv run scripts/inference/vllm_generate.py allenai/olmicro-275m-base "The capital of France is" vllm serve allenai/olmicro-1.4b-base --revision main --dtype bfloat16 --mamba-ssm-cache-dtype float32 ``` Recommended settings (the ones the evals used, and `vllm_generate.py`'s defaults): | Setting | Value | Why | |---|---|---| | `mamba_ssm_cache_dtype` | `float32` | **Required for correct outputs.** Keeps the Gated DeltaNet recurrent state in fp32, as in training and transformers. vLLM's default (the model dtype, bf16) changes the outputs without any error. | | `dtype` | `bfloat16` | the dtype of the weights and of the evals | | `attention_backend` | `FLASH_ATTN` | what the evals used; `TRITON_ATTN` needs no compiled attention kernels and also matches (parity checks on the [`testing`](https://github.com/allenai/olmicro/tree/testing) branch) | | `revision`, `tokenizer_revision` | the branch | vLLM takes the tokenizer from `main` unless told otherwise (all branches ship the same tokenizer) | | `max_model_len` | up to 65,536 | the models were trained to 64k tokens in stage 3; set it lower to save memory. The long-context evals ran past it, to 128k (see [evaluation](evaluation.md)) | **Troubleshooting.** - *`Could not find nvcc and default cuda_home='/usr/local/cuda' doesn't exist`* at engine startup: vLLM's FlashInfer top-k/top-p sampler compiles a kernel the first time and needs the CUDA compiler. Set `VLLM_USE_FLASHINFER_SAMPLER=0` (PyTorch sampler) or point `CUDA_HOME` at a CUDA toolkit. - *`CUDA driver version is insufficient`* with `FLASH_ATTN`: vLLM 0.25's wheels are built for CUDA 13 and need a matching driver (>= 580). Use `attention_backend="TRITON_ATTN"`, or a vLLM build for your CUDA version. - The first engine start compiles and autotunes Triton kernels for a few minutes; later starts are fast. ## Converting Olmo-core checkpoints Every released checkpoint already exists in both formats. Convert your own Olmo-core checkpoints (from [training](training.md)) the same way the release did: ```bash # a released olmo-core checkpoint, as an example (train/ holds data-loader state, not needed here) hf buckets sync hf://buckets/allenai/olmicro-275m-base/stage3/checkpoints/step0047684 ckpt --exclude "train/*" uv run scripts/convert/convert_olmo_core_to_hf.py ckpt hf-model ``` The output directory loads like a published branch (`from_pretrained("hf-model", trust_remote_code=True)`, or `LLM("hf-model", ...)` with the vLLM plugin). The script: 1. converts the weights with `transformers_plugin`'s converter, to bf16 (`--dtype float32` keeps fp32); 2. writes the tokenizer of `allenai/Olmo-3-1025-7B` at a pinned revision (see [Tokenizer](#tokenizer)); 3. copies the plugin's modeling code next to the weights and adds `auto_map` to `config.json`, so the directory loads with `trust_remote_code=True` and no plugin installed. Converting a released checkpoint reproduces the published `model.safetensors`, `tokenizer.json` and modeling code byte for byte; `config.json` differs only in the recorded `transformers_version`, and `tokenizer_config.json` in `is_local` (ignored when loading). The converter unpickles the checkpoint index (`model_and_optim/.metadata`): only convert checkpoints you trust. ## Tokenizer Every branch ships the Olmo 3 tokenizer, `allenai/Olmo-3-1025-7B` (vocabulary 100,278, padded to 100,352 in the embedding; `<|endoftext|>` = 100257 is the end-of-document token, `<|pad|>` = 100277; no BOS token is added). The training configs name `allenai/dolma2-tokenizer`, which has the same vocabulary and special tokens, but the training data was tokenized with the Olmo 3 pre-tokenizer, which splits numbers, tabs and some punctuation differently (`"2024"` is `"202" + "4"`, not `"20" + "24"`). Always load the tokenizer from the model repo. Loading `allenai/Olmo-3-1025-7B` itself with `AutoTokenizer` on transformers 5.15 returns a `GPT2Tokenizer` with GPT-2's pre-tokenizer, i.e. the wrong splits; the model repos avoid this by declaring `TokenizersBackend`, which uses `tokenizer.json` as is. If you load the Olmo 3 tokenizer directly, use `transformers.TokenizersBackend.from_pretrained("allenai/Olmo-3-1025-7B")`.