Skip to content

Commit 7141a28

Browse files
authored
Removed RecipeTuple & RecipeContainer class (#1460)
SUMMARY: Removed RecipeTuple class and downstream dependencies. Updated related docstrings. TEST PLAN: Ran tests from tests/llmcompressor and passed Fixed test_obcq_owl. It was creating event without initializing a session, which shouldn't be allowed. CONCERNS: I did make one assumption that there will be only one `target_stage` each time a session gets initialized. Is it true? --------- Signed-off-by: shanjiaz <[email protected]>
1 parent 9417d5c commit 7141a28

File tree

9 files changed

+61
-275
lines changed

9 files changed

+61
-275
lines changed

src/llmcompressor/core/lifecycle.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
from llmcompressor.core.events import Event, EventType
1414
from llmcompressor.core.state import State
1515
from llmcompressor.modifiers import StageModifiers
16-
from llmcompressor.recipe import (
17-
RecipeArgsInput,
18-
RecipeContainer,
19-
RecipeInput,
20-
RecipeStageInput,
21-
)
16+
from llmcompressor.recipe import Recipe, RecipeArgsInput, RecipeInput, RecipeStageInput
2217

2318
__all__ = ["CompressionLifecycle"]
2419

@@ -30,14 +25,14 @@ class CompressionLifecycle:
3025
3126
:param state: The current state of the compression process
3227
:type state: Optional[State]
33-
:param recipe_container: The container for the compression recipe
34-
:type recipe_container: RecipeContainer
28+
:param recipe: The compression recipe
29+
:type recipe: Recipe
3530
:param modifiers: The list of stage modifiers
3631
:type modifiers: List[StageModifiers]
3732
"""
3833

3934
state: State = field(default_factory=State)
40-
recipe_container: RecipeContainer = field(default_factory=RecipeContainer)
35+
recipe: Recipe = field(default_factory=Recipe)
4136
modifiers: List[StageModifiers] = field(default_factory=list)
4237

4338
initialized_: bool = False
@@ -91,13 +86,16 @@ def initialize(
9186
:return: List of data returned from initialization of modifiers
9287
:rtype: List[Any]
9388
"""
89+
9490
self.state.update(**kwargs)
9591
if self.initialized_: # TODO: do not initialize twice
9692
return
9793

9894
logger.debug("Initializing compression lifecycle")
99-
self.recipe_container.append(recipe, recipe_stage, recipe_args)
100-
self.modifiers = self.recipe_container.get_modifiers()
95+
self.recipe = Recipe.simplify_recipe(
96+
recipe=recipe, target_stage=recipe_stage, override_args=recipe_args
97+
)
98+
self.modifiers = self.recipe.create_modifier()
10199

102100
mod_data = []
103101
for mod in self.modifiers:
@@ -139,8 +137,6 @@ def finalize(self, **kwargs) -> List[Any]:
139137
mod_data.append(data)
140138

141139
self.finalized = True
142-
applied_stage_names = [mod.unique_id for mod in self.modifiers if mod.applied]
143-
self.recipe_container.update_applied_stages(applied_stage_names)
144140

145141
logger.info(
146142
"Compression lifecycle finalized for {} modifiers", len(self.modifiers)

src/llmcompressor/core/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def get_serialized_recipe(self) -> Optional[str]:
213213
"""
214214
:return: serialized string of the current compiled recipe
215215
"""
216-
recipe = self.lifecycle.recipe_container.compiled_recipe
216+
recipe = self.lifecycle.recipe
217217

218218
if recipe is not None and hasattr(recipe, "yaml"):
219219
return recipe.yaml()

src/llmcompressor/core/session_functions.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ def event(cls, event_type: EventType, **kwargs) -> ModifiedState:
7575
f"Use the corresponding method instead."
7676
)
7777

78-
# skip event callbacks if no recipe was provided
79-
if not active_session().lifecycle.recipe_container.check_any_recipe_exists():
80-
return
81-
8278
return active_session().event(event_type, **kwargs)
8379

8480
@classmethod

src/llmcompressor/recipe/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from .base import RecipeBase
2-
from .container import RecipeContainer
32
from .metadata import DatasetMetaData, LayerMetaData, ModelMetaData, ParamMetaData
43
from .modifier import RecipeModifier
5-
from .recipe import Recipe, RecipeArgsInput, RecipeInput, RecipeStageInput, RecipeTuple
4+
from .recipe import Recipe, RecipeArgsInput, RecipeInput, RecipeStageInput
65
from .stage import RecipeStage
76

87
__all__ = [
@@ -11,11 +10,9 @@
1110
"LayerMetaData",
1211
"ModelMetaData",
1312
"RecipeBase",
14-
"RecipeContainer",
1513
"RecipeModifier",
1614
"RecipeStage",
1715
"Recipe",
18-
"RecipeTuple",
1916
"RecipeInput",
2017
"RecipeStageInput",
2118
"RecipeArgsInput",

src/llmcompressor/recipe/container.py

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)