Skip to content

Commit

Permalink
restrict transformers version for now...
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova committed Dec 14, 2023
1 parent 5950d0d commit daefcf3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
12 changes: 0 additions & 12 deletions optimum/intel/openvino/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/openvino/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit daefcf3

Please sign in to comment.