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] Remove pre_initialize_structure #1160

Open
wants to merge 16 commits into
base: kylesayrs/consolidate-saving
Choose a base branch
from

Conversation

kylesayrs
Copy link
Collaborator

@kylesayrs kylesayrs commented Feb 17, 2025

Purpose

  • Remove pre_initialize_structure to simplify codebase
  • Consolidate model saving logic
  • Remove annoying and misleading logging messages
2025-02-17T17:48:38.477750-0500 | _check_create_state | INFO - State created for compression lifecycle
2025-02-17T17:48:38.478670-0500 | pre_initialize_structure | INFO - Compression lifecycle structure pre-initialized for 0 modifiers
2025-02-17T17:48:38.478836-0500 | pre_initialize_structure | INFO - Compression lifecycle structure pre-initialized for 0 modifiers

Prerequisites

Follow-ups

  • Remove double initialization

Changes

The preinitialization step used to fulfill a few purposes

  • Construct the lifecycle state
    • This is now done by the dataclass directly
- state: Optional[State] = None
+ state: Optional[State] = field(default_factory=State)
  • Populate state with model and recipe
    • This is now done (and has always been done) by initialize
    • Some functions such as Trainer.init_model attempt to access the model through the session before initialize is called. In these cases, we can pass the model directly
trainer = Trainer(
-     model_init=get_session_model,
+     model_init=lambda: model,
  • Prepend recipes to the recipe.yaml if the model has already been compressed once
    • Move this logic from preinitialization to the save_pretrained function
    • Consolidate all save pathways to use the the same wrapped method
def save_pretrained_wrapper(...):
    update_and_save_recipe(model.name_or_path, save_directory)
  • Provide a way for modifiers to influence the model after they have already been applied

    • This can still be a enacted via recipe validation, but likely no longer has a use case and shouldn't be done automatically, at most the LLM Compressor should warn if the recipe configuration is invalid / requires modification
  • Create quantization modifier on GPTQ

    • This is now done within the on_initialize function
    • In the future, this should be done by a high-level recipe validation step
def on_initialize(...)
-     self.on_initialize_structure(state, **kwargs)
+     self._maybe_build_quant_modifier(state.model)
  • Remove EventType.order() method which is unused

  • Extend the Recipe.simplify_recipe class method to support strings

Lifecycle

  1. create_session() (doesn't do much and can be hidden behind initialize)
  2. initialize(model=..., recipe=...)
    1. Maybe start modifiers
  3. LifecycleCallback.event(...)
    1. Maybe start/end modifiers
  4. finalize()

Regression Evaluation

Main

vllm (pretrained=/home/kyle/llm-compressor/Meta-Llama-3-8B-Instruct-W4A16-G128,dtype=bfloat16,add_bos_token=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: 1
|  Tasks   |Version|Filter|n-shot|Metric|   |Value |   |Stderr|
|----------|------:|------|-----:|------|---|-----:|---|-----:|
|winogrande|      1|none  |     5|acc   |↑  |0.7482|±  |0.0122|

This branch

vllm (pretrained=/home/kyle/llm-compressor/Meta-Llama-3-8B-Instruct-W4A16-G128,dtype=bfloat16,add_bos_token=True), gen_kwargs: (None), limit: None, num_fewshot: 5, batch_size: 1
|  Tasks   |Version|Filter|n-shot|Metric|   |Value |   |Stderr|
|----------|------:|------|-----:|------|---|-----:|---|-----:|
|winogrande|      1|none  |     5|acc   |↑  |0.7482|±  |0.0122|

Copy link

👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review.

Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed.

@kylesayrs kylesayrs marked this pull request as draft February 17, 2025 19:29
@kylesayrs kylesayrs added the ready When a PR is ready for review label Feb 17, 2025
@kylesayrs kylesayrs marked this pull request as ready for review February 17, 2025 20:47
@kylesayrs kylesayrs self-assigned this Feb 17, 2025
@kylesayrs kylesayrs marked this pull request as draft February 17, 2025 23:28
@kylesayrs kylesayrs removed the ready When a PR is ready for review label Feb 18, 2025
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
@kylesayrs kylesayrs added the ready When a PR is ready for review label Feb 18, 2025
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
@kylesayrs kylesayrs marked this pull request as ready for review February 18, 2025 05:09
@kylesayrs kylesayrs changed the base branch from main to kylesayrs/consolidate-saving February 18, 2025 21:18
Signed-off-by: Kyle Sayers <[email protected]>
Signed-off-by: Kyle Sayers <[email protected]>
Copy link
Collaborator

@horheynm horheynm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready When a PR is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants