aien-sovereign-core
Autonomous sovereign intelligence engine and runtime core for NVIDIA DGX Spark
Brought by drakestapleton
aien-sovereign-core / modular / nemotron_h_kvexp / model.py
| 1 | """Pipeline model subclass that uses the KV-expanded config.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from typing import Any |
| 6 | |
| 7 | from max.graph import DeviceRef |
| 8 | from max.pipelines.architectures.nemotron_h.model import NemotronHModel |
| 9 | |
| 10 | from .config import KvExpandedNemotronHConfig |
| 11 | |
| 12 | |
| 13 | class KvExpandedNemotronHModel(NemotronHModel): |
| 14 | """NemotronHModel whose config replicates KV heads (GQA group <= 8). |
| 15 | |
| 16 | The built-in ``_create_model_config`` hardcodes ``NemotronHConfig.from_hf``, |
| 17 | so we must override it to route through the expanded config. Everything else |
| 18 | (graph build, state pools, batching) is inherited unchanged. |
| 19 | """ |
| 20 | |
| 21 | model_config_cls = KvExpandedNemotronHConfig |
| 22 | |
| 23 | def _create_model_config(self, state_dict: dict[str, Any]): |
| 24 | device_ref = DeviceRef.from_device(self.devices[0]) |
| 25 | model_config = KvExpandedNemotronHConfig.from_hf( |
| 26 | self.pipeline_config, |
| 27 | self.huggingface_config, |
| 28 | self.dtype, |
| 29 | self.kv_params, |
| 30 | [device_ref], |
| 31 | ) |
| 32 | model_config.populate_fp8_layers(state_dict) |
| 33 | return model_config |