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
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion src/llmcompressor/pytorch/model_load/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def load_safetensors_state_dict(file_path: str) -> Dict[str, torch.Tensor]:
return {key: f.get_tensor(key) for key in f.keys()}


def copy_python_files_from_model_cache(model, save_path: str):
def copy_python_files_from_model_cache(model: Module, save_path: str):
config = model.config
cache_path = None
if hasattr(config, "_name_or_path"):
Expand Down
14 changes: 12 additions & 2 deletions tests/llmcompressor/transformers/obcq/test_consecutive_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ def _test_consecutive_runs(
import math

from llmcompressor.core import active_session
from llmcompressor.pytorch.model_load.helpers import get_session_model
from llmcompressor.pytorch.model_load.helpers import (
get_session_model,
initialize_recipe,
)
from llmcompressor.pytorch.utils.helpers import tensor_sparsity
from llmcompressor.transformers import oneshot
from llmcompressor.transformers.utils.helpers import resolve_recipe
from llmcompressor.utils.pytorch import qat_active

# test recipe with 50% sparsity, quantization and smoothquant
Expand All @@ -49,9 +53,13 @@ def _test_consecutive_runs(
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)

horheynm marked this conversation as resolved.
Show resolved Hide resolved
# 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 +72,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