economize.core¶
Techniques, the recipe that attaches them, the model wrapper and persistence. The names that economize re-exports
at the package root, such as TechniqueConfig, EfficientModel and apply, are documented in
economize. This page lists the remaining ones.
Techniques, the recipe that attaches them, the model wrapper and persistence.
CAPABILITY_ORDER
module-attribute
¶
CAPABILITY_ORDER: tuple[Capability, ...] = (Capability.WEIGHTS, Capability.ACTIVATIONS, Capability.KV_CACHE, Capability.DEPTH, Capability.DRAFTER)
GENERATE_IMPLEMENTATIONS
module-attribute
¶
GENERATE_IMPLEMENTATIONS: Registry[GenerateFn] = Registry('generate implementation')
GenerateFn
¶
Bases: Protocol
A transformers-compatible generate, called as fn(model, inputs, **generate_kwargs): the token ids,
or a transformers generate output when return_dict_in_generate=True.
attach_rank
¶
Sort key of the recipe: capability group (:data:CAPABILITY_ORDER, NONE last), then :attr:order.
attach_techniques
¶
attach_techniques(model: Module, adapter: ArchAdapter, configs: Sequence[TechniqueConfig], *, states: States | None = None, calibration: object = None, options: Mapping[str, object] | None = None) -> list[Technique]
Build the techniques of configs, load states (before anything attaches) and attach them in order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The base model (unwrapped). |
required |
adapter
|
ArchAdapter
|
Its architecture adapter. |
required |
configs
|
Sequence[TechniqueConfig]
|
One configuration per technique, in any order. |
required |
states
|
States | None
|
Saved state per technique name (from a checkpoint). A technique without an entry is built as
:func: |
None
|
calibration
|
object
|
Calibration data for techniques that need it (see :class: |
None
|
options
|
Mapping[str, object] | None
|
Free-form options for third-party techniques. |
None
|
Returns:
| Type | Description |
|---|---|
list[Technique]
|
The attached techniques in attach order. |
A technique that attaches on a simulated path (:meth:Technique.simulation) gives a
:class:~economize.SimulatedPathWarning.
If an attach fails, the techniques attached so far are detached in reverse order before the error propagates. Weight transforms cannot be undone; the error then notes that the base model was (or, for the transform that failed, may have been) modified. A detach that fails during this roll-back is noted on the original error.
build_model
¶
build_model(model: Module, configs: Sequence[TechniqueConfig], *, decoding: DecodeConfig | None = None, calibration: object = None, states: States | None = None) -> EfficientModel
:func:apply that also loads saved technique states before the techniques attach (used by
:func:economize.attach for checkpoints).
build_techniques
¶
build_techniques(adapter: ArchAdapter, configs: Sequence[TechniqueConfig], states: States | None = None) -> list[Technique]
Construct the techniques of configs in attach order, check that they combine and load states.
Nothing is attached and the base model is not modified. On a model split by tensor parallelism the techniques'
replicated parameters are made equal to those of the first process (a collective call, see
:func:~economize.modules.sharding.replicate_from_first_rank).
Raises:
| Type | Description |
|---|---|
IncompatibleTechniquesError
|
A technique appears twice, or a technique's
:meth: |
CheckpointFormatError
|
|
technique_for
¶
technique_for(config: TechniqueConfig) -> type[Technique]
The registered technique class that builds config.