> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/automodel/_mcp/server.

# nemo_automodel.components.speculative.precompute_dspark

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

| Name                                                                                                              | Description                                                           |
| ----------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [`_build_parser`](#nemo_automodel-components-speculative-precompute_dspark-_build_parser)                         | -                                                                     |
| [`_ensure_resume_compatible`](#nemo_automodel-components-speculative-precompute_dspark-_ensure_resume_compatible) | Refuse to resume into shards produced with a different configuration. |
| [`_run`](#nemo_automodel-components-speculative-precompute_dspark-_run)                                           | Load the target, scan the dataset once, and write the sharded cache.  |
| [`_validate_args`](#nemo_automodel-components-speculative-precompute_dspark-_validate_args)                       | Reject invalid CLI values before loading the target model.            |
| [`main`](#nemo_automodel-components-speculative-precompute_dspark-main)                                           | CLI entry point. Parses `argv` and returns the process exit code.     |

### Data

[`_UNSUPPORTED_OFFLINE_TARGET_MODEL_TYPES`](#nemo_automodel-components-speculative-precompute_dspark-_UNSUPPORTED_OFFLINE_TARGET_MODEL_TYPES)

[`logger`](#nemo_automodel-components-speculative-precompute_dspark-logger)

### API

```python
nemo_automodel.components.speculative.precompute_dspark._build_parser() -> argparse.ArgumentParser
```

```python
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.

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

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

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

Reject invalid CLI values before loading the target model.

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

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

```python
nemo_automodel.components.speculative.precompute_dspark._UNSUPPORTED_OFFLINE_TARGET_MODEL_TYPES = (_DEEPSEEK_V4_MODEL_TYPE, _GLM_5_2_MODEL_TYPE, *_MINIMAX_M3_MODEL_TYPES)
```

```python
nemo_automodel.components.speculative.precompute_dspark.logger = logging.getLogger(__name__)
```