llmcompressor.recipe.utils
append_recipe_dict(d1, d2)
Merge two recipe dicts by renaming top-level stage keys to numbered versions.
If both have the same stage key (e.g. 'test_stage'), the result will contain: 'test_stage_0', 'test_stage_1', etc.
Always starts numbering from 0 even for the first occurrence.
Source code in llmcompressor/recipe/utils.py
filter_dict(obj, target_stage=None)
Filter a dictionary to only include keys that match the target stage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | dict | The recipe dictionary to filter. | required |
target_stage | Optional[str] | The stage to filter by (e.g., 'test_stage'). | None |
Returns:
Type | Description |
---|---|
dict | A new dictionary containing only the keys that match the target stage. |
Source code in llmcompressor/recipe/utils.py
get_yaml_serializable_dict(modifiers, stage)
This function is used to convert a list of modifiers into a dictionary where the keys are the group names and the values are the modifiers which in turn are dictionaries with the modifier type as the key and the modifier args as the value. This is needed to conform to our recipe structure during yaml serialization where each stage, modifier_groups, and modifiers are represented as valid yaml dictionaries.
Note: This function assumes that modifier groups do not contain the same modifier type more than once in a group. This assumption is also held by Recipe.create_instance(...) method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
modifiers | List[Modifier] | A list of dictionaries where each dictionary holds all information about a modifier | required |
Returns:
Type | Description |
---|---|
Dict[str, Any] | A dictionary where the keys are the group names and the values are the modifiers which in turn are dictionaries with the modifier type as the key and the modifier args as the value. |