llmcompressor.recipe.utils
Functions:
-
append_recipe_dict
–Merge two recipe dicts by renaming top-level stage keys to numbered versions.
-
filter_dict
–Filter a dictionary to only include keys that match the target stage.
-
get_yaml_serializable_dict
–This function is used to convert a list of modifiers into a dictionary
append_recipe_dict
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
Filter a dictionary to only include keys that match the target stage.
Parameters:
-
obj
dict
) –The recipe dictionary to filter.
-
target_stage
Optional[str]
, default:None
) –The stage to filter by (e.g., 'test_stage').
Returns:
-
dict
–A new dictionary containing only the keys that match the target stage.
Source code in llmcompressor/recipe/utils.py
get_yaml_serializable_dict
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:
-
modifiers
List[Modifier]
) –A list of dictionaries where each dictionary holds all information about a modifier
Returns:
-
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.