nemo_automodel._transformers.v4_patches.layer_types#
Widen transformers’ ALLOWED_LAYER_TYPES so legacy custom configs load.
Some community models (e.g. nvidia/Nemotron-Flash-1B) ship a custom
configuration_*.py whose layer_types entries (e.g. 'deltanet',
'f', 'm2', 'a') are not in the upstream allow-list. Loading them
via AutoConfig.from_pretrained triggers validate_layer_type and raises
StrictDataclassClassValidationError before model instantiation.
The validator performs a module-global lookup of ALLOWED_LAYER_TYPES at
call time, so rebinding it in place takes effect on subsequent validations.
Module Contents#
Classes#
Meta-path finder that applies |
Functions#
Extend |
|
Ensure |
|
No-op replacement for |
|
Disable |
Data#
API#
- nemo_automodel._transformers.v4_patches.layer_types.logger#
‘getLogger(…)’
- nemo_automodel._transformers.v4_patches.layer_types._TARGET_MODULE#
‘transformers.configuration_utils’
- nemo_automodel._transformers.v4_patches.layer_types.DEFAULT_EXTRA_LAYER_TYPES: tuple[str, ...]#
(‘deltanet’, ‘f’, ‘m2’, ‘a’)
- nemo_automodel._transformers.v4_patches.layer_types._PATCHED: bool#
False
- nemo_automodel._transformers.v4_patches.layer_types.patch_allowed_layer_types(
- extra: Iterable[str] = DEFAULT_EXTRA_LAYER_TYPES,
Extend
transformers.configuration_utils.ALLOWED_LAYER_TYPESin place.Idempotent and best-effort: any failure (missing attribute, transformers not installed, unexpected container type) is logged and swallowed so the caller’s import path is not broken.
- Parameters:
extra – Layer-type names to append if not already present.
- Returns:
Trueif the tuple was modified on this call,Falseotherwise.
- nemo_automodel._transformers.v4_patches.layer_types._HOOK_INSTALLED: bool#
False
- class nemo_automodel._transformers.v4_patches.layer_types._LayerTypesPatchFinder[source]#
Bases:
importlib.abc.MetaPathFinderMeta-path finder that applies
patch_allowed_layer_typesthe momenttransformers.configuration_utilsfinishes loading.The finder only intercepts the single target module name. For that name it delegates to the remaining finders to obtain a real spec, then wraps the loader’s
exec_moduleso the patch runs once, post-exec. All deviations from the happy path (missing loader, unexpected spec shape, patch failure) are swallowed with a log — the finder must never break imports.Initialization
- nemo_automodel._transformers.v4_patches.layer_types.install_layer_types_patch_hook() bool[source]#
Ensure
patch_allowed_layer_typesruns before any call toPreTrainedConfig.validate_layer_type.Two paths:
If
transformers.configuration_utilsis already loaded, patch immediately.Otherwise, register a meta-path finder that patches on first import.
Idempotent; safe to call multiple times.
- Returns:
Trueif a hook was installed (or the patch was applied directly on this call),Falseif a previous call already arranged one.
- nemo_automodel._transformers.v4_patches.layer_types._VALIDATOR_RELAXED: bool#
False
- nemo_automodel._transformers.v4_patches.layer_types._noop_validate_layer_type(self)[source]#
No-op replacement for
PretrainedConfig.validate_layer_type.
- nemo_automodel._transformers.v4_patches.layer_types.relax_layer_types_validator() bool[source]#
Disable
PretrainedConfig.validate_layer_typeand its registered copies.Some upstream configs (e.g.
stepfun-ai/Step-3.5-Flash) shiplayer_typeswhose length differs fromnum_hidden_layers; newer transformers rejects such configs, andhuggingface_hubwraps thatValueErrorinStrictDataclassClassValidationError. Suppressing the validator lets downstream code load the config unmodified.The
huggingface_hub@strictdecorator freezes validator references on each class into__class_validators__at decoration time, so swappingPretrainedConfig.validate_layer_typealone is insufficient: every already-decorated subclass keeps its own list. This helper rewrites both the class attribute and each list entry across the live subclass tree, then newly-decorated subclasses pick up the no-op automatically viagetattr(cls, "validate_layer_type")at their decoration time.Idempotent and best-effort: failures (missing attribute, transformers not installed) are logged and swallowed so the caller is never broken.
- Returns:
Trueif the patch was applied on this call,Falseotherwise.
- nemo_automodel._transformers.v4_patches.layer_types.__all__#
[‘DEFAULT_EXTRA_LAYER_TYPES’, ‘install_layer_types_patch_hook’, ‘patch_allowed_layer_types’, ‘relax_…