|
8 | 8 | from torch.nn import Module
|
9 | 9 |
|
10 | 10 | from llmcompressor.core import active_session, create_session, pre_initialize_structure
|
11 |
| -from llmcompressor.pytorch.utils import ModuleSparsificationInfo |
12 | 11 | from llmcompressor.typing import Processor
|
13 | 12 |
|
14 | 13 | COMPLETED_STAGES_FILENAME = "completed_stages.json"
|
15 | 14 |
|
16 | 15 | __all__ = [
|
17 |
| - "log_model_load", |
18 | 16 | "initialize_recipe",
|
19 | 17 | "save_model_and_recipe",
|
20 | 18 | "copy_python_files_from_model_cache",
|
|
26 | 24 | ]
|
27 | 25 |
|
28 | 26 |
|
29 |
| -def log_model_load( |
30 |
| - model: Module, model_name_or_path: str, model_type: str, delayed_load: bool |
31 |
| -): |
32 |
| - """ |
33 |
| - Log the state of a loaded model including sparsity and |
34 |
| - prunable params information. |
35 |
| -
|
36 |
| - :param model: the loaded model |
37 |
| - :param model_name_or_path: the original name of or path to the model that loaded |
38 |
| - :param model_type: specify the type of model loaded for logging; |
39 |
| - ex one of [model, student, teacher] |
40 |
| - :param delayed_load: True if this model load was delayed until after |
41 |
| - recipe instantiation due to QAT or other architectural state changes |
42 |
| - """ |
43 |
| - if delayed_load: |
44 |
| - logger.info( |
45 |
| - f"Delayed load of model {model_name_or_path} detected. " |
46 |
| - f"Will print out model information once LLMCompressor recipes have loaded" |
47 |
| - ) |
48 |
| - return |
49 |
| - |
50 |
| - sparsification_info = ModuleSparsificationInfo(model) |
51 |
| - |
52 |
| - logger.info( |
53 |
| - f"Loaded {model_type} from {model_name_or_path} " |
54 |
| - f"with {sparsification_info.params_total} total params. " |
55 |
| - f"Of those there are {sparsification_info.params_prunable_total} prunable " |
56 |
| - f"params which have {sparsification_info.params_prunable_sparse_percent} " |
57 |
| - "avg sparsity." |
58 |
| - ) |
59 |
| - model_type = ( |
60 |
| - "sparse" if sparsification_info.params_prunable_sparse_percent > 5 else "dense" |
61 |
| - ) |
62 |
| - logger.info( |
63 |
| - f"{model_type} model detected, " |
64 |
| - f"all sparsification info: {sparsification_info}" |
65 |
| - ) |
66 |
| - |
67 |
| - |
68 | 27 | def initialize_recipe(model: Module, recipe_path: str):
|
69 | 28 | """
|
70 | 29 | Initializes a recipe that has been previously applied to the model
|
|
0 commit comments