core.models.hybrid.layers.utils#
Module Contents#
Classes#
Symbols for different layer types and pattern separators. |
Functions#
Return whether |
|
Create a layer-specific config from a normalized stack-level config. |
|
Return the canonical symbol for a layer config. |
|
Validate TP communication overlap support for built-in hybrid layers. |
API#
- class core.models.hybrid.layers.utils.Symbols#
Symbols for different layer types and pattern separators.
- MAMBA#
‘M’
- GDN#
‘G’
- ATTENTION#
‘*’
- DS_ATTENTION#
‘D’
- MLA#
‘+’
- MLP#
‘-’
- MOE#
‘E’
- PIPE#
‘|’
- MTP_SEPARATOR#
‘/’
- LAYER_CONFIG_MAP#
None
- ATTENTION_LAYER_CONFIGS#
None
- classmethod name_sorted_valid_layer_symbols() list[str]#
Return valid layer symbols sorted by their public attribute names.
- core.models.hybrid.layers.utils.is_valid_symbol(layer_symbol: str, allow_pipe: bool = False) bool#
Return whether
layer_symbolidentifies a supported layer or allowed pipe.- Parameters:
layer_symbol – Symbol to validate.
allow_pipe – Whether to also accept the pipeline separator symbol.
- core.models.hybrid.layers.utils.create_layer_config(
- config: megatron.core.transformer.transformer_config.TransformerConfig,
- layer_symbol: str,
Create a layer-specific config from a normalized stack-level config.
- Parameters:
config – Normalized stack-level config to copy.
layer_symbol – Symbol identifying the layer config type to create.
- Returns:
An independent config of the type corresponding to
layer_symbol.- Raises:
ValueError – If
layer_symboldoes not identify a supported hybrid layer.
- core.models.hybrid.layers.utils.get_layer_symbol_from_config(
- layer_config: megatron.core.transformer.transformer_config.TransformerConfig,
Return the canonical symbol for a layer config.
- Parameters:
layer_config – Layer config whose hybrid symbol should be returned.
- Returns:
The symbol corresponding to
layer_config.- Raises:
ValueError – If the exact config type is unsupported.
- core.models.hybrid.layers.utils.validate_tp_comm_overlap(
- config: megatron.core.transformer.transformer_config.TransformerConfig,
- segment: str,
- has_mtp: bool = False,
Validate TP communication overlap support for built-in hybrid layers.
- Parameters:
config – Config whose TP communication overlap setting should be validated.
segment – Layer symbols governed by
config.has_mtp – Whether this model instance will build an MTP block.
- Raises:
ValueError – If TP communication overlap is enabled with MLA, DSA, or MTP.