Skip to navigation
ReferenceFull Library ReferenceNemo AutomodelNemo AutomodelComponentsModelsQwen2 5 Omninemo_automodel.components.models.qwen2_5_omni.state_dict_adapter

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter

View as MarkdownOpen in Claude

Module Contents

Classes

NameDescription
Qwen2_5OmniStateDictAdapterHF Qwen2.5-Omni checkpoint adapter (thinker-only path).

Data

_CHECKPOINT_TO_MODULE_PREFIXES

_DROP_PREFIXES

_DROP_THINKER_KEY_SUBSTRINGS

_MODULE_PREFIXES

_PEFT_PREFIX

_THINKER_PREFIX

logger

API

class nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter(
config: typing.Any,
dtype: torch.dtype = torch.float32
)

Bases: StateDictAdapter

HF Qwen2.5-Omni checkpoint adapter (thinker-only path).

HF Qwen/Qwen2.5-Omni-* checkpoints store keys under three top-level prefixes: thinker.*, talker.*, token2wav.*. For ASR/text fine-tuning we only train the Thinker, so this adapter:

  • on from_hf: drops talker.* and token2wav.* keys, strips the thinker. prefix, and moves the published names (audio_tower.*, visual.*, model.*) to the module layout of Transformers 5.22 (model.audio_tower.*, model.visual.*, model.language_model.*). Names already in the module layout pass through, so checkpoints and adapters written in either layout load.
  • on to_hf: writes base weights under the published names with the thinker. prefix, so the loader requests names the original shards contain and saved checkpoints can be merged back with the original talker/token2wav shards. PEFT tensors keep the module names, which HF PEFT resolves against the Transformers 5.22 model.

Qwen2.5-Omni-3B is dense (no MoE), so no expert grouping logic is needed — this is a thin key-renaming adapter.

backend
= backend or BackendConfig()
nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter._add_thinker_prefix(
key: str
) -> str
staticmethod

Namespace a native key the way the HF omni checkpoint expects.

PEFT adapter keys keep their base_model.model. outer prefix, so for those the thinker. namespace goes inside it — matching how PEFT names modules on the actual HF omni model.

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter._strip_thinker_prefix(
key: str
) -> str
staticmethod

Remove the omni checkpoint’s thinker. namespace.

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter._to_checkpoint_layout(
name: str
) -> str
staticmethod

Map a Transformers 5.22 thinker module name to the published name.

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter._to_hf_key(
key: str
) -> str

Name a native key the way the HF omni checkpoint stores it.

Base weights take the published names. PEFT tensors keep the module names, because HF PEFT matches them against the model’s modules.

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter._to_module_key(
key: str
) -> str
classmethod

Move a thinker-relative key, PEFT-prefixed or not, to the module layout.

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter._to_module_layout(
name: str
) -> str
staticmethod

Map a published thinker name to the Transformers 5.22 module name.

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter.convert_single_tensor_to_hf(
fqn: str,
tensor: typing.Any,
kwargs = {}
) -> list[tuple[str, typing.Any]]

Rename one native key to its HF checkpoint name; tensor passes through unchanged.

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter.from_hf(
hf_state_dict: dict[str, typing.Any],
device_mesh: typing.Any | None = None,
kwargs = {}
) -> dict[str, typing.Any]

Rename HF Qwen2.5-Omni checkpoint keys to native keys.

Parameters:

hf_state_dict
dict[str, Any]

HF state dict; tensor values of any shape pass through unchanged.

device_mesh
Any | NoneDefaults to None

Unused; the dense model has no expert sharding.

Returns: dict[str, Any]

The thinker’s values under native names, without talker, token2wav and deleted keys.

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter.map_peft_target_module_to_hf(
name: str,
v4_compatible: bool = False
) -> str

Namespace adapter_config.json target_modules the way the tensors are namespaced.

PEFT suffix-matches target_modules against the receiving model, so on the full omni layout an entry without thinker. also hits the talker’s structurally identical submodules and injects adapters the saved file has no weights for. This follows _uses_thinker_prefix the same way to_hf and convert_single_tensor_to_hf do, so the hook and the tensor exporters stay aligned.

Parameters:

name
str

A target-module name in native layout.

v4_compatible
boolDefaults to False

Legacy export selection; omni uses one module layout for both.

Returns: str

Target-module name in the layout the exported tensors use.

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.Qwen2_5OmniStateDictAdapter.to_hf(
state_dict: dict[str, typing.Any],
exclude_key_regex: str | None = None,
quantization: bool = False,
kwargs = {}
) -> dict[str, typing.Any]

Rename native keys to the HF Qwen2.5-Omni checkpoint names.

Parameters:

state_dict
dict[str, Any]

Native state dict; tensor values of any shape pass through unchanged.

exclude_key_regex
str | NoneDefaults to None

Drop converted keys that match this pattern.

quantization
boolDefaults to False

Unused; the adapter does not quantize.

Returns: dict[str, Any]

The same values under their HF checkpoint names.

nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter._CHECKPOINT_TO_MODULE_PREFIXES = (('audio_tower.', 'model.audio_tower.'), ('visual.', 'model.visual.'), ('model.'...
nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter._DROP_PREFIXES = ('talker.', 'token2wav.')
nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter._DROP_THINKER_KEY_SUBSTRINGS = ('audio_tower.audio_bos_eos_token',)
nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter._MODULE_PREFIXES = tuple(module for _, module in _CHECKPOINT_TO_MODULE_PREFIXES)
nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter._PEFT_PREFIX = 'base_model.model.'
nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter._THINKER_PREFIX = 'thinker.'
nemo_automodel.components.models.qwen2_5_omni.state_dict_adapter.logger = logging.getLogger(__name__)