Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Callbacks][Docs] Add docstrings to saving functions #1201

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9b3e216
remove pre_initialize_structure
kylesayrs Feb 17, 2025
3bff7d1
remove preinit event
kylesayrs Feb 17, 2025
14e47a5
remove order test
kylesayrs Feb 17, 2025
c6a9e6b
Merge branch 'main' into kylesayrs/remove-preinitialize-structure
kylesayrs Feb 17, 2025
6b882bb
consolodate saving
kylesayrs Feb 18, 2025
bb35a74
typos
kylesayrs Feb 18, 2025
71903ff
add todos
kylesayrs Feb 18, 2025
d39d375
dreggs, style
kylesayrs Feb 18, 2025
7cc5a6d
typo
kylesayrs Feb 18, 2025
9865fa3
adjust typehint
kylesayrs Feb 18, 2025
68ce624
allow prepending
kylesayrs Feb 18, 2025
5b7cc03
check saved recipe contents
kylesayrs Feb 18, 2025
bdc4fa5
consolidate saving paths
kylesayrs Feb 18, 2025
a83b0aa
remove broken import
kylesayrs Feb 18, 2025
4efd116
Merge remote-tracking branch 'origin' into kylesayrs/consolidate-saving
kylesayrs Feb 18, 2025
b9f0bd1
add back def
kylesayrs Feb 18, 2025
29ab794
Merge remote-tracking branch 'origin' into kylesayrs/remove-preinitia…
kylesayrs Feb 18, 2025
0a2642b
save state
kylesayrs Feb 18, 2025
0c70881
Merge branch 'kylesayrs/consolidate-saving' into kylesayrs/remove-pre…
kylesayrs Feb 18, 2025
60371ef
remove verbose messages
kylesayrs Feb 18, 2025
bf9a8cd
fix double initialization
kylesayrs Feb 18, 2025
3d64d57
rename function
kylesayrs Feb 25, 2025
55984c4
remove accidentally added files
kylesayrs Feb 25, 2025
05fa5f6
Merge remote-tracking branch 'origin' into kylesayrs/remove-preinitia…
kylesayrs Feb 25, 2025
53d762e
Merge remote-tracking branch 'origin' into kylesayrs/remove-preinitia…
kylesayrs Feb 25, 2025
e026658
add debug statement
kylesayrs Feb 25, 2025
00961a0
pass model to stage runner
kylesayrs Feb 25, 2025
c7678b0
remove breakpoint
kylesayrs Feb 26, 2025
97a0dd2
add docstrings
kylesayrs Feb 26, 2025
fafefff
Merge remote-tracking branch 'origin' into kylesayrs/add-saving-docst…
kylesayrs Mar 10, 2025
0486f7a
Merge branch 'main' into kylesayrs/add-saving-docstring
kylesayrs Mar 10, 2025
cf73646
Merge branch 'main' into kylesayrs/add-saving-docstring
kylesayrs Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/llmcompressor/pytorch/model_load/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@
def save_checkpoint(
save_path: str,
model: PreTrainedModel,
processor: Processor,
processor: Optional[Processor] = None,
save_safetensors: bool = True,
save_compressed: bool = True,
):
"""
Save a model, processor, and recipe

:param save_path: Path used to save model and processor
:param model: model to save
:param processor: processor to save
:param save_safetensors: save model checkpoint using safetensors file type
:param save_compressed: save model checkpoint using compressed-tensors format
"""
# saving the model also saves the recipe
model.save_pretrained(
save_path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
def modify_save_pretrained(model: PreTrainedModel):
"""
Overrides a PreTrainedModel's save_pretrained() method with a wrapped version that
supports compression
supports compression. The new save_pretrained function performs the following saving
operations:

1. Saves the model state, potentially in a compressed format
2. Saves the recipe, appending any current recipes to existing recipe files
3. Copies any necessary python files from the model cache
"""

def save_pretrained_compressed(save_pretrained_method):
Expand Down Expand Up @@ -254,9 +259,16 @@ def get_model_compressor(
)


def update_and_save_recipe(model_path: str, save_directory: str):
def update_and_save_recipe(model_stub: str, save_directory: str):
"""
Save a recipe ontop of any existing recipe files located at model_stub

:param model_stub: path to existing model or model stub which may contain an
existing recipe
:param save_directory: path to save combined existing recipe and current recipe
"""
recipes_to_save = []
existing_recipe = infer_recipe_from_model_path(model_path)
existing_recipe = infer_recipe_from_model_path(model_stub)
if existing_recipe is not None:
recipes_to_save.append(existing_recipe)

Expand Down
Loading