llmcompressor.entrypoints.utils
Utility functions for entrypoint pre and post-processing operations.
Provides common utility functions used by training and one-shot compression entrypoints. Includes model loading, configuration setup, preprocessing steps, and post-processing operations for compression workflows.
Functions:
-
get_processor_name_from_model
–Get a processor/tokenizer source used for both student and teacher, assuming
-
post_process
–Saves the model and tokenizer/processor to the output directory if model_args,
-
pre_process
–Prepares the model and tokenizer/processor for calibration.
get_processor_name_from_model
Get a processor/tokenizer source used for both student and teacher, assuming that they could be shared
Parameters:
-
student
Module
) –the student model
-
teacher
Optional[Module]
) –the teacher model
Returns:
-
str
–the source for the processor/tokenizer shared between teacher and model
Source code in llmcompressor/entrypoints/utils.py
post_process
post_process(
model_args: Optional[ModelArguments] = None,
recipe_args: Optional[RecipeArguments] = None,
output_dir: Optional[str] = None,
)
Saves the model and tokenizer/processor to the output directory if model_args, output_dir is provided.
Save is skipped for stage runs for train
- saves using the trainer.save_model()
If the output_dir
is not the default directory, the method resets lifecycle actions. The model is saved in a compressed format if specified in model_args
. Additionally, the tokenizer or processor, if available, is also saved.
Raises: ValueError: If saving fails due to an invalid output_dir
or other issues.
Source code in llmcompressor/entrypoints/utils.py
pre_process
Prepares the model and tokenizer/processor for calibration. - Initializes the model if it's specified as a path or string. - Applies patches to fix tied tensor issues and modifies save_pretrained
behavior. - Initializes the processor if specified as a path or None
. - Sets the minimum tokens per module if dataset_args
are provided. Raises: FileNotFoundError: If the model or processor path is invalid.