Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 tests/e2e/vLLM/test_vllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def test_vllm(self, test_data_file: str):
self.tear_down()

def tear_down(self):
if self.save_dir is not None:
if self.save_dir is not None and os.path.isdir(self.save_dir):
shutil.rmtree(self.save_dir)

timer = get_singleton_manager()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import os
import shutil
import tempfile
import unittest
Expand Down Expand Up @@ -128,7 +129,8 @@ def test_hf_quantizer_decompress_match_manual_decompress(self):

@classmethod
def tearDownClass(self):
shutil.rmtree(self.test_dir)
if os.path.isdir(self.test_dir):
shutil.rmtree(self.test_dir)
del self.dense_model
del self.decompressed_model_hf_quantizer
del self.decompressed_model_manual
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.test_dir)
if os.path.isdir(cls.test_dir):
shutil.rmtree(cls.test_dir)
del cls.model
torch.cuda.empty_cache()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import tempfile
import unittest
Expand Down Expand Up @@ -82,7 +83,8 @@ def test_compressed_matches_decompressed(self):

@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.test_dir)
if os.path.isdir(cls.test_dir):
shutil.rmtree(cls.test_dir)
del cls.decompressed_model
del cls.uncompressed_model
torch.cuda.empty_cache()
Expand Down Expand Up @@ -167,7 +169,8 @@ def test_compressed_matches_decompressed__hf_quantizer(self):

@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.test_dir)
if os.path.isdir(cls.test_dir):
shutil.rmtree(cls.test_dir)
del cls.decompressed_model
del cls.compressed_model
torch.cuda.empty_cache()
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def create_mock_file(self, extension, content, path, filename):
return mock_filepath # Return the file path

def tearDown(self):
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)


@pytest.mark.integration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import unittest
from pathlib import Path
Expand Down Expand Up @@ -46,4 +47,5 @@ def test_oneshot_with_modifier_object(self):
)

def tearDown(self):
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import unittest

Expand Down Expand Up @@ -41,4 +42,5 @@ def test_finetune_without_recipe(self):
)

def tearDown(self):
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def _test_oneshot_and_finetune(self):
def tearDown(self):
# TODO: we get really nice stats from finetune that we should log
# stored in results.json
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)


@pytest.mark.integration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import unittest

Expand Down Expand Up @@ -78,4 +79,5 @@ def test_oneshot_and_finetune_with_tokenizer(self):
print(tokenizer.decode(output[0]))

def tearDown(self):
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import unittest
from pathlib import Path
Expand Down Expand Up @@ -175,4 +176,5 @@ def test_oneshot_quantization_then_finetune(self):
)

def tearDown(self):
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ def test_safetensors(self):
)

def tearDown(self):
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)
4 changes: 3 additions & 1 deletion tests/llmcompressor/transformers/gptq/test_oneshot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import unittest

Expand Down Expand Up @@ -113,4 +114,5 @@ def test_oneshot_application(self):
assert not hasattr(not_targetted, "quantization_scheme")

def tearDown(self):
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import unittest
from pathlib import Path
Expand Down Expand Up @@ -109,7 +110,8 @@ def _test_consecutive_runs(
self.assertEqual(stage1_modifier_names, exp_stage1_modifier_names)

def tearDown(self):
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)


@pytest.mark.integration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import unittest

Expand Down Expand Up @@ -90,7 +91,8 @@ def _test_oneshot_completion(self, model_name: str = None):
self.assertLess(avg_new_ppl, self.perplexity)

def tearDown(self):
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)


@requires_gpu
Expand Down
7 changes: 5 additions & 2 deletions tests/llmcompressor/transformers/obcq/test_obcq_sparsity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
import os
import shutil
import unittest

Expand Down Expand Up @@ -48,7 +49,8 @@ def test_sparsities(self):
def tearDown(self):
import torch

shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)
torch.cuda.empty_cache()


Expand Down Expand Up @@ -97,5 +99,6 @@ def test_sparsities_gpu(self):
def tearDown(self):
import torch

shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)
torch.cuda.empty_cache()
4 changes: 3 additions & 1 deletion tests/llmcompressor/transformers/oneshot/test_api_inputs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import unittest

Expand Down Expand Up @@ -62,4 +63,5 @@ def test_one_shot_inputs(self):
)

def tearDown(self):
shutil.rmtree(self.output)
if os.path.isdir(self.output):
shutil.rmtree(self.output)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
import os
import shutil

import pytest
Expand Down Expand Up @@ -115,7 +116,8 @@ def test_sparse_model_reload(compressed, config, dtype, tmp_path):
assert dense_tensor.dtype == reconstructed_tensor.dtype == dtype
assert torch.equal(dense_tensor, reconstructed_tensor)

shutil.rmtree(tmp_path)
if os.path.isdir(tmp_path):
shutil.rmtree(tmp_path)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -145,7 +147,8 @@ def test_dense_model_save(tmp_path, skip_compression_stats, save_compressed):
sparsity_config = ModelCompressor.parse_sparsity_config(compression_config)
assert sparsity_config is None

shutil.rmtree(tmp_path)
if os.path.isdir(tmp_path):
shutil.rmtree(tmp_path)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -223,7 +226,8 @@ def test_quant_model_reload(format, dtype, tmp_path):
assert not torch.any(diff > 0.01).item()
else:
assert torch.equal(dense_tensor, reconstructed_tensor)
shutil.rmtree(tmp_path)
if os.path.isdir(tmp_path):
shutil.rmtree(tmp_path)


# technically only tie_word_embeddings=False is supported right now
Expand Down Expand Up @@ -435,7 +439,8 @@ def test_compressor_stacking(model_stub, recipe, sparse_format, quant_format, tm
assert not torch.any(diff > 0.025), f"Max diff: {torch.max(diff)}"
else:
assert torch.equal(dense_tensor, reconstructed_tensor)
shutil.rmtree(tmp_path)
if os.path.isdir(tmp_path):
shutil.rmtree(tmp_path)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -503,7 +508,8 @@ def test_sparse_24_compressor_is_lossless(model_stub, recipe, sparse_format, tmp
assert dense_tensor.dtype == reconstructed_tensor.dtype
if key.endswith("weight"):
assert torch.equal(dense_tensor, reconstructed_tensor)
shutil.rmtree(tmp_path)
if os.path.isdir(tmp_path):
shutil.rmtree(tmp_path)


def test_disable_sparse_compression_flag(tmp_path):
Expand All @@ -530,7 +536,8 @@ def test_disable_sparse_compression_flag(tmp_path):

assert sparsity_config
assert sparsity_config["format"] == "dense"
shutil.rmtree(tmp_path)
if os.path.isdir(tmp_path):
shutil.rmtree(tmp_path)


class DummyLinearModel(nn.Module):
Expand Down
2 changes: 1 addition & 1 deletion tests/lmeval/test_lmeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ def tear_down(self):
df = pd.DataFrame(measurements)
df.to_csv(p / f"{self.save_dir}.csv", index=False)

if self.save_dir is not None:
if self.save_dir is not None and os.path.isdir(self.save_dir):
shutil.rmtree(self.save_dir)