From daefcf3f67fcdd0592d74d4c62c81067834b06f0 Mon Sep 17 00:00:00 2001 From: eaidova Date: Fri, 3 Nov 2023 18:34:12 +0400 Subject: [PATCH] restrict transformers version for now... --- optimum/intel/openvino/trainer.py | 12 ------------ tests/openvino/test_modeling.py | 6 +++--- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/optimum/intel/openvino/trainer.py b/optimum/intel/openvino/trainer.py index 9cf31868e9..f5badac7b6 100644 --- a/optimum/intel/openvino/trainer.py +++ b/optimum/intel/openvino/trainer.py @@ -637,13 +637,10 @@ def _inner_training_loop( if args.max_grad_norm is not None and args.max_grad_norm > 0: # deepspeed does its own clipping -<<<<<<< HEAD -======= if getattr(self, "do_grad_scaling", False): # AMP: gradients need unscaling self.scaler.unscale_(self.optimizer) ->>>>>>> fix tests if is_sagemaker_mp_enabled() and args.fp16: self.optimizer.clip_master_grads(args.max_grad_norm) elif self.use_apex: @@ -659,14 +656,6 @@ def _inner_training_loop( ) # Optimizer step -<<<<<<< HEAD - self.optimizer.step() - optimizer_was_run = not self.accelerator.optimizer_step_was_skipped - if optimizer_was_run: - # Delay optimizer scheduling until metrics are generated - if not isinstance(self.lr_scheduler, torch.optim.lr_scheduler.ReduceLROnPlateau): - self.lr_scheduler.step() -======= optimizer_was_run = True if self.deepspeed: pass # called outside the loop @@ -681,7 +670,6 @@ def _inner_training_loop( if optimizer_was_run and not self.deepspeed: self.lr_scheduler.step() ->>>>>>> fix tests model.zero_grad() self.state.global_step += 1 diff --git a/tests/openvino/test_modeling.py b/tests/openvino/test_modeling.py index 17ead588cd..3a7cf02a00 100644 --- a/tests/openvino/test_modeling.py +++ b/tests/openvino/test_modeling.py @@ -494,7 +494,7 @@ def test_compare_to_transformers(self, model_arch): set_seed(SEED) ov_model = OVModelForCausalLM.from_pretrained(model_id, export=True) self.assertIsInstance(ov_model.config, PretrainedConfig) - transformers_model = AutoModelForCausalLM.from_pretrained(model_id) + transformers_model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float32) tokenizer = AutoTokenizer.from_pretrained(model_id) tokens = tokenizer( "This is a sample", return_tensors="pt", return_token_type_ids=False if model_arch == "llama" else None @@ -510,7 +510,8 @@ def test_compare_to_transformers(self, model_arch): with torch.no_grad(): transformers_outputs = transformers_model(**tokens) # Compare tensor outputs - self.assertTrue(torch.allclose(ov_outputs.logits, transformers_outputs.logits, atol=1e-2)) + self.assertTrue(torch.allclose(ov_outputs.logits, transformers_outputs.logits, atol=1e-4), + f"Max diff {torch.abs(ov_outputs.logits - transformers_outputs.logits).max()}") del transformers_model del ov_model gc.collect() @@ -1244,7 +1245,6 @@ def test_compare_to_transformers(self, model_arch): ov_outputs = ov_model(**features, **decoder_inputs) self.assertIn("logits", ov_outputs) - self.assertIsInstance(ov_outputs.logits, TENSOR_ALIAS_TO_TYPE[input_type]) # Compare tensor outputs self.assertTrue(torch.allclose(torch.Tensor(ov_outputs.logits), transformers_outputs.logits, atol=1e-3))