replacement_utils

This module provides helper functions for parsing, sorting, and analyzing layer replacement configurations used in the replacement library for model compression.

Functions

parse_layer_replacement

extract_block_configs_and_locations

weights_path_to_checkpoint_dir

replacement_is_teacher

is_replacement_identical_to_teacher

split_replacements_to_teacher_and_student

extract_block_configs_and_locations(layer_replacements)
Parameters:

layer_replacements (list[dict])

Return type:

tuple[list[BlockConfig], list[tuple[dict, int]]]

is_replacement_identical_to_teacher(layer_replacement, teacher_model_config)
Parameters:
  • layer_replacement (dict)

  • teacher_model_config (PreTrainedConfig)

Return type:

bool

parse_layer_replacement(layer_replacement)
Parameters:

layer_replacement (dict | str)

Return type:

dict

replacement_is_teacher(layer_replacement, teacher_model_config, teacher_checkpoint_dir)
Parameters:
  • layer_replacement (dict)

  • teacher_model_config (PreTrainedConfig)

  • teacher_checkpoint_dir (Path)

Return type:

bool

split_replacements_to_teacher_and_student(replacements, teacher_model_config, teacher_checkpoint_dir)
Parameters:
  • replacements (list[dict])

  • teacher_model_config (PreTrainedConfig)

  • teacher_checkpoint_dir (Path)

Return type:

tuple[list[dict], list[dict]]

weights_path_to_checkpoint_dir(weights_path)
Parameters:

weights_path (Path)

Return type:

Path