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

fix consecutive oneshot #898

Closed
wants to merge 8 commits into from
Closed
Changes from 2 commits
Commits
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
13 changes: 11 additions & 2 deletions tests/llmcompressor/transformers/obcq/test_consecutive_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def _test_consecutive_runs(
from llmcompressor.pytorch.utils.helpers import tensor_sparsity
from llmcompressor.transformers import oneshot
from llmcompressor.utils.pytorch import qat_active

from llmcompressor.transformers.utils.helpers import resolve_recipe
from llmcompressor.pytorch.model_load.helpers import initialize_recipe

# test recipe with 50% sparsity, quantization and smoothquant
oneshot(
Expand All @@ -48,10 +51,14 @@ def _test_consecutive_runs(
stages = [stage.group for stage in session_recipe.stages]
self.assertEqual(len(stages), 1)
session.reset()


recipe = resolve_recipe(recipe=self.first_recipe, model_path=self.output_first)
kylesayrs marked this conversation as resolved.
Show resolved Hide resolved
if recipe:
initialize_recipe(model=first_tiny_model, recipe_path=recipe)

# reload saved model and up sparsity to 0.7
oneshot(
model=self.output_first,
model=first_tiny_model,
dataset=self.dataset,
num_calibration_samples=num_calibration_samples,
recipe=self.second_recipe,
Expand All @@ -64,12 +71,14 @@ def _test_consecutive_runs(
layer_0_sparse = tensor_sparsity(
second_tiny_model.model.layers[0].self_attn.k_proj.weight
)

assert math.isclose(layer_0_sparse.item(), 0.7, rel_tol=tolerance)
assert qat_active(second_tiny_model)

session = active_session()
session_recipe = session.lifecycle.recipe_container.compiled_recipe
stages = [stage.group for stage in session_recipe.stages]

self.assertEqual(len(stages), 2)

recipe_path = self.output_second / "recipe.yaml"
Expand Down
Loading