ruff format

This commit is contained in:
JiwenJ 2025-04-20 06:52:26 +00:00
parent 88840ee45a
commit c808083e39
2 changed files with 22 additions and 68 deletions

View File

@ -24,6 +24,4 @@ else:
import sys
_file = globals()["__file__"]
sys.modules[__name__] = _LazyModule(
__name__, _file, define_import_structure(_file), module_spec=__spec__
)
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)

View File

@ -121,20 +121,14 @@ class PLMModelTester:
token_type_ids = None
if self.use_token_type_ids:
token_type_ids = ids_tensor(
[self.batch_size, self.seq_length], self.type_vocab_size
)
token_type_ids = ids_tensor([self.batch_size, self.seq_length], self.type_vocab_size)
sequence_labels = None
token_labels = None
choice_labels = None
if self.use_labels:
sequence_labels = ids_tensor(
[self.batch_size], self.type_sequence_label_size
)
token_labels = ids_tensor(
[self.batch_size, self.seq_length], self.num_labels
)
sequence_labels = ids_tensor([self.batch_size], self.type_sequence_label_size)
token_labels = ids_tensor([self.batch_size, self.seq_length], self.num_labels)
choice_labels = ids_tensor([self.batch_size], self.num_choices)
config = self.get_config()
@ -239,9 +233,7 @@ class PLMModelTester:
model.to(torch_device)
model.eval()
result = model(input_ids, attention_mask=input_mask, labels=token_labels)
self.parent.assertEqual(
result.logits.shape, (self.batch_size, self.seq_length, self.vocab_size)
)
self.parent.assertEqual(result.logits.shape, (self.batch_size, self.seq_length, self.vocab_size))
def create_and_check_decoder_model_past_large_inputs(
self,
@ -297,17 +289,13 @@ class PLMModelTester:
# select random slice
random_slice_idx = ids_tensor((1,), output_from_past.shape[-1]).item()
output_from_no_past_slice = output_from_no_past[
:, -3:, random_slice_idx
].detach()
output_from_no_past_slice = output_from_no_past[:, -3:, random_slice_idx].detach()
output_from_past_slice = output_from_past[:, :, random_slice_idx].detach()
self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1])
# test that outputs are equal for slice
self.parent.assertTrue(
torch.allclose(output_from_past_slice, output_from_no_past_slice, atol=1e-3)
)
self.parent.assertTrue(torch.allclose(output_from_past_slice, output_from_no_past_slice, atol=1e-3))
def prepare_config_and_inputs_for_common(self):
config_and_inputs = self.prepare_config_and_inputs()
@ -325,9 +313,7 @@ class PLMModelTester:
@require_torch
class PLMModelTest(
ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase
):
class PLMModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase):
# breakpoint()
all_model_classes = (
(
@ -402,21 +388,15 @@ class PLMModelTest(
def test_contrastive_generate_low_memory(self):
pass
@unittest.skip(
"PLM has HybridCache and doesn't support StaticCache. Though it could, it shouldn't support."
)
@unittest.skip("PLM has HybridCache and doesn't support StaticCache. Though it could, it shouldn't support.")
def test_generate_with_static_cache(self):
pass
@unittest.skip(
"PLM has HybridCache and doesn't support StaticCache. Though it could, it shouldn't support."
)
@unittest.skip("PLM has HybridCache and doesn't support StaticCache. Though it could, it shouldn't support.")
def test_generate_from_inputs_embeds_with_static_cache(self):
pass
@unittest.skip(
"PLM has HybridCache and doesn't support StaticCache. Though it could, it shouldn't support."
)
@unittest.skip("PLM has HybridCache and doesn't support StaticCache. Though it could, it shouldn't support.")
def test_generate_continue_from_inputs_embeds(self):
pass
@ -424,27 +404,19 @@ class PLMModelTest(
def test_sdpa_equivalence(self):
pass
@unittest.skip(
"PLM uses MLA so it is not compatible with the standard cache format"
)
@unittest.skip("PLM uses MLA so it is not compatible with the standard cache format")
def test_beam_search_generate_dict_outputs_use_cache(self):
pass
@unittest.skip(
"PLM uses MLA so it is not compatible with the standard cache format"
)
@unittest.skip("PLM uses MLA so it is not compatible with the standard cache format")
def test_generate_compilation_all_outputs(self):
pass
@unittest.skip(
"PLM uses MLA so it is not compatible with the standard cache format"
)
@unittest.skip("PLM uses MLA so it is not compatible with the standard cache format")
def test_generate_compile_model_forward(self):
pass
@unittest.skip(
"PLM uses MLA so it is not compatible with the standard cache format"
)
@unittest.skip("PLM uses MLA so it is not compatible with the standard cache format")
def test_greedy_generate_dict_outputs_use_cache(self):
pass
@ -576,9 +548,7 @@ class PLMIntegrationTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
if is_torch_available() and torch.cuda.is_available():
cls.cuda_compute_capability_major_version = (
torch.cuda.get_device_capability()[0]
)
cls.cuda_compute_capability_major_version = torch.cuda.get_device_capability()[0]
@slow
@require_torch_accelerator
@ -604,43 +574,29 @@ class PLMIntegrationTest(unittest.TestCase):
"Simply put, the theory of relativity states that ",
"My favorite all time favorite condiment is ketchup.",
]
tokenizer = AutoTokenizer.from_pretrained(
"PLM-Team/PLM-1.8B-Base", use_fast=False
)
tokenizer = AutoTokenizer.from_pretrained("PLM-Team/PLM-1.8B-Base", use_fast=False)
model = PLMForCausalLM.from_pretrained(
"PLM-Team/PLM-1.8B-Base", device_map=torch_device, torch_dtype=torch.float16
)
inputs = tokenizer(prompts, return_tensors="pt", padding=True).to(model.device)
# Dynamic Cache
generated_ids = model.generate(
**inputs, max_new_tokens=NUM_TOKENS_TO_GENERATE, do_sample=False
)
generated_ids = model.generate(**inputs, max_new_tokens=NUM_TOKENS_TO_GENERATE, do_sample=False)
dynamic_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
self.assertEqual(EXPECTED_TEXT_COMPLETION, dynamic_text)
# Static Cache
generated_ids = model.generate(
**inputs,
max_new_tokens=NUM_TOKENS_TO_GENERATE,
do_sample=False,
cache_implementation="static"
**inputs, max_new_tokens=NUM_TOKENS_TO_GENERATE, do_sample=False, cache_implementation="static"
)
static_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
self.assertEqual(EXPECTED_TEXT_COMPLETION, static_text)
# Static Cache + compile
model._cache = None # clear cache object, initialized when we pass `cache_implementation="static"`
model.forward = torch.compile(
model.forward, mode="reduce-overhead", fullgraph=True
)
model.forward = torch.compile(model.forward, mode="reduce-overhead", fullgraph=True)
generated_ids = model.generate(
**inputs,
max_new_tokens=NUM_TOKENS_TO_GENERATE,
do_sample=False,
cache_implementation="static"
)
static_compiled_text = tokenizer.batch_decode(
generated_ids, skip_special_tokens=True
**inputs, max_new_tokens=NUM_TOKENS_TO_GENERATE, do_sample=False, cache_implementation="static"
)
static_compiled_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
self.assertEqual(EXPECTED_TEXT_COMPLETION, static_compiled_text)