Apply ruff flake8-comprehensions (#21694)
This commit is contained in:
@@ -1148,7 +1148,13 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
||||
# won't be the same since the training dataloader is shuffled).
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
kwargs = dict(output_dir=tmpdir, train_len=128, save_steps=5, learning_rate=0.1, logging_steps=5)
|
||||
kwargs = {
|
||||
"output_dir": tmpdir,
|
||||
"train_len": 128,
|
||||
"save_steps": 5,
|
||||
"learning_rate": 0.1,
|
||||
"logging_steps": 5,
|
||||
}
|
||||
trainer = get_regression_trainer(**kwargs)
|
||||
trainer.train()
|
||||
(a, b) = trainer.model.a.item(), trainer.model.b.item()
|
||||
@@ -1181,7 +1187,13 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
||||
|
||||
# With a regular model that is not a PreTrainedModel
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
kwargs = dict(output_dir=tmpdir, train_len=128, save_steps=5, learning_rate=0.1, pretrained=False)
|
||||
kwargs = {
|
||||
"output_dir": tmpdir,
|
||||
"train_len": 128,
|
||||
"save_steps": 5,
|
||||
"learning_rate": 0.1,
|
||||
"pretrained": False,
|
||||
}
|
||||
|
||||
trainer = get_regression_trainer(**kwargs)
|
||||
trainer.train()
|
||||
|
||||
@@ -108,8 +108,8 @@ class TrainerCallbackTest(unittest.TestCase):
|
||||
self.assertEqual(len(cbs1), len(cbs2))
|
||||
|
||||
# Order doesn't matter
|
||||
cbs1 = list(sorted(cbs1, key=lambda cb: cb.__name__ if isinstance(cb, type) else cb.__class__.__name__))
|
||||
cbs2 = list(sorted(cbs2, key=lambda cb: cb.__name__ if isinstance(cb, type) else cb.__class__.__name__))
|
||||
cbs1 = sorted(cbs1, key=lambda cb: cb.__name__ if isinstance(cb, type) else cb.__class__.__name__)
|
||||
cbs2 = sorted(cbs2, key=lambda cb: cb.__name__ if isinstance(cb, type) else cb.__class__.__name__)
|
||||
|
||||
for cb1, cb2 in zip(cbs1, cbs2):
|
||||
if isinstance(cb1, type) and isinstance(cb2, type):
|
||||
|
||||
@@ -189,7 +189,7 @@ class TrainerUtilsTest(unittest.TestCase):
|
||||
# The biggest element should be first
|
||||
self.assertEqual(lengths[indices[0]], 50)
|
||||
# The indices should be a permutation of range(100)
|
||||
self.assertEqual(list(sorted(indices)), list(range(100)))
|
||||
self.assertEqual(sorted(indices), list(range(100)))
|
||||
|
||||
def test_group_by_length_with_dict(self):
|
||||
# Get some inputs of random lengths
|
||||
@@ -204,7 +204,7 @@ class TrainerUtilsTest(unittest.TestCase):
|
||||
# The biggest element should be first
|
||||
self.assertEqual(len(data[indices[0]]["input_ids"]), 105)
|
||||
# The indices should be a permutation of range(6)
|
||||
self.assertEqual(list(sorted(indices)), list(range(6)))
|
||||
self.assertEqual(sorted(indices), list(range(6)))
|
||||
|
||||
def test_group_by_length_with_batch_encoding(self):
|
||||
# Get some inputs of random lengths
|
||||
@@ -219,7 +219,7 @@ class TrainerUtilsTest(unittest.TestCase):
|
||||
# The biggest element should be first
|
||||
self.assertEqual(len(data[indices[0]]["input_ids"]), 105)
|
||||
# The indices should be a permutation of range(6)
|
||||
self.assertEqual(list(sorted(indices)), list(range(6)))
|
||||
self.assertEqual(sorted(indices), list(range(6)))
|
||||
|
||||
def test_distributed_length_grouped(self):
|
||||
# Get some inputs of random lengths
|
||||
@@ -232,7 +232,7 @@ class TrainerUtilsTest(unittest.TestCase):
|
||||
# The biggest element should be first
|
||||
self.assertEqual(lengths[indices_process_0[0]], 50)
|
||||
# The indices should be a permutation of range(100)
|
||||
self.assertEqual(list(sorted(indices_process_0 + indices_process_1)), list(range(100)))
|
||||
self.assertEqual(sorted(indices_process_0 + indices_process_1), list(range(100)))
|
||||
|
||||
def test_get_parameter_names(self):
|
||||
model = nn.Sequential(TstLayer(128), nn.ModuleList([TstLayer(128), TstLayer(128)]))
|
||||
|
||||
Reference in New Issue
Block a user