cerebras.modelzoo.tools.checkpoint_converters.base_converter.BaseDictionaryConverter#
- class cerebras.modelzoo.tools.checkpoint_converters.base_converter.BaseDictionaryConverter(pbar_desc=None)[source]#
Bases:
abc.ABC
A dictionary converter represents a pair of two dictionary formats that can be converted between each other. The converter object defines a list of conversion rules which should be applied when converting one dict format to the other (and vice-versa).
In order to make your own dictionary converter, simply: 1. Create a new converter class which inherits from BaseDictionaryConverter 2. Supply a list of conversion rules (self.rules) 3. Override the pre_model_convert or post_model_convert hooks if you
need to execute arbitrary behavior before/after the conversion.
Methods
convert_all_keys
Attempts to convert the old key by matching against the list of conversion rules.
formats
get_converter_indices
match_indices
Copies value that exists at old_state_dict's old_key to new_state_dict's new_key.
supports_conversion
- static replaceKey(old_key, new_key, old_state_dict, new_state_dict, from_index, action_fn_args=None)[source]#
Copies value that exists at old_state_dict’s old_key to new_state_dict’s new_key.
- convert_key(old_key, old_state_dict, new_state_dict, from_index, match_start=0, prefix='', action_fn_args=None, debug=False)[source]#
Attempts to convert the old key by matching against the list of conversion rules. The first rule to match is used for conversion (i.e. even if multiple rules would match, the latter ones are never used). Returns True if a conversion occurred.