cerebras.modelzoo.tools.checkpoint_converters.base_converter.BaseDictionaryConverter#

class cerebras.modelzoo.tools.checkpoint_converters.base_converter.BaseDictionaryConverter[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

convert_key

Attempts to convert the old key by matching against the list of conversion rules.

formats

get_converter_indices

replaceKey

Copies value that exists at old_state_dict's old_key to new_state_dict's new_key.

supports_conversion

__init__(pbar_desc=None)[source]#
static replaceKey(old_key: str, new_key: str, old_state_dict: collections.OrderedDict, new_state_dict: collections.OrderedDict, from_index: int, action_fn_args: Optional[dict] = None) None[source]#

Copies value that exists at old_state_dict’s old_key to new_state_dict’s new_key.

convert_key(old_key: str, old_state_dict: collections.OrderedDict, new_state_dict: collections.OrderedDict, from_index: int, match_start: int = 0, prefix: str = '', action_fn_args: Optional[dict] = None, debug: bool = False) None[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.