Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪄 Minor comment style modif #2582

Merged
merged 1 commit into from
Jan 17, 2025
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
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
Loading