Skip to navigation

nemo_automodel.components.speculative.precompute_dspark

View as MarkdownOpen in Claude

Precompute the DSpark offline target-supervision cache.

The online DSpark recipe runs a frozen target model every step to capture the intermediate target hidden states consumed by the draft and the final hidden state used by the TV / confidence losses. This script runs that target once and writes those tensors to disk. Training can then set recipe_args.cached_target_path to stream the cache without loading or running the target model.

Typical usage (single device):

python -m nemo_automodel.components.speculative.precompute_dspark
—target-model Qwen/Qwen3-0.6B
—input-data /data/messages.jsonl
—output-dir /data/dspark_cache/qwen3_06b
—seq-length 2048 —batch-size 4 —shard-size 256 —dtype bf16

Module Contents

Functions

NameDescription
_build_parser-
_ensure_resume_compatibleRefuse to resume into shards produced with a different configuration.
_is_kimi_k3_text_exportTell a Kimi K3 text-only export from Kimi-Linear-48B; both write model_type: kimi_linear.
_json_objectParse a --chat-template-kwargs value, which must be a JSON object.
_runLoad the target, scan the dataset once, and write the sharded cache.
_validate_argsReject invalid CLI values before loading the target model.
mainCLI entry point. Parses argv and returns the process exit code.

Data

_UNSUPPORTED_OFFLINE_TARGET_MODEL_TYPES

logger

API

nemo_automodel.components.speculative.precompute_dspark._build_parser() -> argparse.ArgumentParser
nemo_automodel.components.speculative.precompute_dspark._ensure_resume_compatible(
cache_dir: str,
manifest: dict[str, typing.Any],
existing_shards: set[int]
) -> None

Refuse to resume into shards produced with a different configuration.

nemo_automodel.components.speculative.precompute_dspark._is_kimi_k3_text_export(
target_path: str,
trust_remote_code: bool
) -> bool

Tell a Kimi K3 text-only export from Kimi-Linear-48B; both write model_type: kimi_linear.

Only K3 writes attn_res_block_size to its config, and no published Kimi-Linear-48B config has it.

nemo_automodel.components.speculative.precompute_dspark._json_object(
value: str
) -> dict[str, typing.Any]

Parse a --chat-template-kwargs value, which must be a JSON object.

nemo_automodel.components.speculative.precompute_dspark._run(
args: argparse.Namespace
) -> int

Load the target, scan the dataset once, and write the sharded cache.

nemo_automodel.components.speculative.precompute_dspark._validate_args(
args: argparse.Namespace
) -> None

Reject invalid CLI values before loading the target model.

nemo_automodel.components.speculative.precompute_dspark.main(
argv: list[str] | None = None
) -> int

CLI entry point. Parses argv and returns the process exit code.

nemo_automodel.components.speculative.precompute_dspark._UNSUPPORTED_OFFLINE_TARGET_MODEL_TYPES = (_DEEPSEEK_V4_MODEL_TYPE, _DEEPSEEK_V41_MODEL_TYPE, _GLM_5_2_MODEL_TYPE, 'kimi_k...
nemo_automodel.components.speculative.precompute_dspark.logger = logging.getLogger(__name__)