Skip to content

Model loading ​

Use this reference to choose model and tokenizer sources, control checkpoint loading, and configure remote code. It also describes checkpoint prefetch and rank-sharded loading behavior.

Command-line parameters ​

The following table lists the parameters for selecting model and tokenizer sources and controlling checkpoint loading:

ParameterPurpose
positional modelModel path or Hugging Face repo ID.
--modelEquivalent to positional model.
--tokenizerTokenizer path when it differs from the model path.
--tokenizer-modeSelect tokenizer behavior. auto uses fast tokenizers and model-specific hooks when available.
--load-formatWeight loading format: auto, pt, safetensors, runai_streamer, npcache, dummy, or extensible. runai_streamer requires runai-model-streamer>=0.16.1 and streams safetensors from local paths or object-store URIs (gs://, s3://).
--model-loader-extra-configOptional JSON object of loader-specific options. For runai_streamer options, see Run:ai model streamer options on this page.
--trust-remote-codeAllow custom model code from the model repository. ts serve forwards this flag to SMG when enabled, allowing its Python chat renderer fallback. Disabled by default on the CLI.
--revisionModel branch, tag, or commit.
--download-dirHugging Face download/cache directory.
--hf-overridesJSON overrides for model configuration values.

Run:ai model streamer options ​

To install the dependency required by runai_streamer with TokenSpeed, run pip install "tokenspeed[runai]". Pass the following options in --model-loader-extra-config:

  • concurrency: A positive integer.
  • memory_limit: A non-negative integer number of bytes.
  • distributed: A Boolean value.
  • distributed_scope: "local" or "global". This option is required when distributed is true and rejected when distributed is false:
    • "local" sets RUNAI_STREAMER_DIST_GLOBAL=0 to broadcast within each node.
    • "global" sets RUNAI_STREAMER_DIST_GLOBAL=1 to shard reads and broadcast across all hosts in the default NCCL process group.

Distributed streaming requires CUDA and a multi-rank process group with NCCL serving CUDA. It pins RUNAI_STREAMER_DIST=1 and streams through cuda:<rank>, subject to runai-model-streamer's internal 2 * max_chunk free-VRAM check.

The loader copies yielded tensors out of streamer staging buffers to standalone CPU storage in both distributed and non-distributed modes.

Remote code ​

When you construct ServerArgs or ModelConfig in Python, remote code is disabled by default. Pass trust_remote_code=True to allow custom code from the model repository.

Checkpoint file permissions ​

Safetensors checkpoints only need read permission. The loader does not create shared writable mappings of source shards. Models that need shared writable host storage must own separate working storage.

Checkpoint prefetch and TP shards ​

Safetensors loading prefetches checkpoints into the OS page cache. Ranks on the same node divide background reads in sorted shard order. Every node prefetches its own copy. Each reader keeps the full consumption order within the existing window of min(40 GiB, 25% of available host memory), including shards assigned to peers. Reads remain asynchronous: a consumer does not wait for another rank and can demand-page an unfinished peer shard. Models with rank-dependent weight-name filters prefetch independently. Use --disable-weight-loader-prefetch-checkpoints to disable prefetch or --weight-loader-prefetch-num-threads to set reader concurrency per rank.

Rank-sharded state loading ​

The programmatic LoadConfig(load_format="sharded_state") loader reads only the current global rank's files, named model-rank-{rank}-part-{part}.safetensors by default. These are post-processed runtime state dictionaries, not ordinary Hugging Face shards. Reload with the same model configuration, parallel mapping, quantization, and runtime weight layout. The loader constructs and post-processes the model before copying the saved state into it. Check compatibility for the model and quantization in use. Keep model configuration/tokenizer files with the checkpoint. Pass a custom filename pattern through LoadConfig.model_loader_extra_config, for example {"pattern": "model-rank-{rank}-part-{part}.safetensors"}. The serving CLI does not expose this loader or its extra configuration.

TokenSpeed documentation