Skip to content

Commit

Permalink
🪄 Minor comment style modif (#2582)
Browse files Browse the repository at this point in the history
  • Loading branch information
qgallouedec authored Jan 17, 2025
1 parent 57d9a97 commit 5877786
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 72 deletions.
20 changes: 8 additions & 12 deletions tests/test_bco_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ def test_bco_trainer(self, name, pre_compute, eval_dataset, config_name):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param.cpu(), new_param.cpu()))

@require_sklearn
Expand Down Expand Up @@ -220,11 +219,10 @@ def test_bco_trainer_without_providing_ref_model(self):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param.cpu(), new_param.cpu()))

@require_sklearn
Expand Down Expand Up @@ -268,11 +266,10 @@ def embed_prompt(input_ids, attention_mask, model):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param.cpu(), new_param.cpu()))

@require_sklearn
Expand Down Expand Up @@ -318,12 +315,11 @@ def test_bco_trainer_without_providing_ref_model_with_lora(self):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
if "lora" in n:
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param.cpu(), new_param.cpu()))

@require_sklearn
Expand Down
10 changes: 4 additions & 6 deletions tests/test_cpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ def test_cpo_trainer(self, name, loss_type, config_name):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param, new_param))

@parameterized.expand(
Expand Down Expand Up @@ -147,10 +146,9 @@ def test_cpo_trainer_with_lora(self, config_name):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
if "lora" in n:
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param, new_param))
35 changes: 14 additions & 21 deletions tests/test_dpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,10 @@ def test_dpo_trainer(self, name, loss_type, pre_compute):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.allclose(param, new_param, rtol=1e-12, atol=1e-12))

def test_dpo_trainer_with_weighting(self):
Expand Down Expand Up @@ -277,11 +276,10 @@ def test_dpo_trainer_with_weighting(self):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.allclose(param, new_param, rtol=1e-12, atol=1e-12))

@parameterized.expand(
Expand Down Expand Up @@ -323,11 +321,10 @@ def test_dpo_trainer_without_providing_ref_model(self, rpo_alpha, _):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param, new_param))

def test_dpo_trainer_with_ref_model_is_model(self):
Expand Down Expand Up @@ -377,11 +374,10 @@ def test_precompute_ref_batch_size(self):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.allclose(param, new_param, rtol=1e-12, atol=1e-12))

@require_peft
Expand Down Expand Up @@ -428,12 +424,11 @@ def test_dpo_trainer_without_providing_ref_model_with_lora(self):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
if "lora" in n:
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param, new_param))

def test_dpo_trainer_padding_token_is_none(self):
Expand Down Expand Up @@ -537,11 +532,10 @@ def test_tr_dpo_trainer(self):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.ref_model.get_parameter(n)
# check the ref model's params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param, new_param))

@require_no_wandb
Expand Down Expand Up @@ -1190,11 +1184,10 @@ def test_padding_free(self):

trainer.train()

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.allclose(param, new_param, rtol=1e-12, atol=1e-12))


Expand Down
15 changes: 6 additions & 9 deletions tests/test_kto_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ def test_kto_trainer(self, name, config_name, loss_type, pre_compute, eval_datas

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param, new_param))

def test_kto_trainer_with_ref_model_is_model(self):
Expand Down Expand Up @@ -238,11 +237,10 @@ def test_kto_trainer_without_providing_ref_model(self):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param, new_param))

@require_peft
Expand Down Expand Up @@ -288,12 +286,11 @@ def test_kto_trainer_without_providing_ref_model_with_lora(self):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
if "lora" in n:
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param, new_param))

@require_no_wandb
Expand Down
10 changes: 4 additions & 6 deletions tests/test_orpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ def test_orpo_trainer(self, name, config_name):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param, new_param))

@parameterized.expand(
Expand Down Expand Up @@ -141,10 +140,9 @@ def test_orpo_trainer_with_lora(self, config_name):

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
if "lora" in n:
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.equal(param, new_param))
14 changes: 6 additions & 8 deletions tests/test_prm_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,10 @@ def test_train_full(self, train_on_last_step_only):
trainer.train()

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])
# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.allclose(param, new_param, rtol=1e-12, atol=1e-12))

def test_train_full_pretokenized(self):
Expand Down Expand Up @@ -266,11 +265,10 @@ def test_train_full_pretokenized(self):
trainer.train()

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])
# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.allclose(param, new_param, rtol=1e-12, atol=1e-12))

@require_peft
Expand Down Expand Up @@ -309,12 +307,12 @@ def test_train_lora(self):

self.assertIsNotNone(trainer.state.log_history[(-1)]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
self.assertFalse(torch.allclose(param, new_param, atol=1e-12, rtol=1e-12))

# check the non trainable params have not changed
# Check that the non trainable parameters have not changed
for n, param in previous_non_trainable_params.items():
new_param = trainer.model.get_parameter(n)
self.assertTrue(torch.allclose(param, new_param, atol=1e-12, rtol=1e-12))
Expand Down
18 changes: 8 additions & 10 deletions tests/test_reward_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ def test_train_full(self):
trainer.train()

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])
# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.allclose(param, new_param, rtol=1e-12, atol=1e-12))

def test_train_full_pretokenized(self):
Expand All @@ -90,11 +89,10 @@ def test_train_full_pretokenized(self):
trainer.train()

self.assertIsNotNone(trainer.state.log_history[-1]["train_loss"])
# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
# check the params have changed - ignore 0 biases
if param.sum() != 0:
if param.sum() != 0: # ignore 0 biases
self.assertFalse(torch.allclose(param, new_param, rtol=1e-12, atol=1e-12))

@require_peft
Expand Down Expand Up @@ -133,12 +131,12 @@ def test_train_lora(self):

self.assertIsNotNone(trainer.state.log_history[(-1)]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
self.assertFalse(torch.allclose(param, new_param, atol=1e-12, rtol=1e-12))

# check the non trainable params have not changed
# Check that the non trainable parameters have not changed
for n, param in previous_non_trainable_params.items():
new_param = trainer.model.get_parameter(n)
self.assertTrue(torch.allclose(param, new_param, atol=1e-12, rtol=1e-12))
Expand Down Expand Up @@ -181,12 +179,12 @@ def test_train_lora_pretokenized(self):

self.assertIsNotNone(trainer.state.log_history[(-1)]["train_loss"])

# check the params have changed
# Check that the parameters have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
self.assertFalse(torch.allclose(param, new_param, atol=1e-12, rtol=1e-12))

# check the non trainable params have not changed
# Check that the non trainable parameters have not changed
for n, param in previous_non_trainable_params.items():
new_param = trainer.model.get_parameter(n)
self.assertTrue(torch.allclose(param, new_param, atol=1e-12, rtol=1e-12))
Expand Down

0 comments on commit 5877786

Please sign in to comment.