patcher

Functions

deci_x_patcher

Context manager that patches decoder layer __init__ for heterogeneous per-layer configs.

override_config_with_block_configs

Create a copy of config with block_config overrides applied.

deci_x_patcher(model_descriptor, block_configs=None)

Context manager that patches decoder layer __init__ for heterogeneous per-layer configs.

This is the core mechanism that enables AnyModel to work with any HuggingFace model. It patches the decoder layer class(es) to read per-layer block_configs and apply layer-specific overrides (e.g., different intermediate_size per layer).

Parameters:
  • model_descriptor (ModelDescriptor) – The model descriptor that defines which classes to patch and how to map block_configs to layer overrides.

  • block_configs (List[BlockConfig | dict] | None) – Optional list of BlockConfig (one per layer). If not provided, will try to read from config.block_configs during model initialization.

Example

>>> with deci_x_patcher(LlamaModelDescriptor, block_configs):
...     model = AutoModelForCausalLM.from_config(config)
override_config_with_block_configs(config, block_configs)

Create a copy of config with block_config overrides applied.

Parameters:
  • config (PreTrainedConfig)

  • block_configs (Dict[str, Any])

Return type:

PreTrainedConfig