mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-04 21:30:07 +06:00
replace directly-specified-test-dirs with tmp_dir
This commit is contained in:
parent
d911458b59
commit
310a6d962e
@ -552,10 +552,10 @@ if is_torch_available():
|
|||||||
compute_metrics = kwargs.pop("compute_metrics", None)
|
compute_metrics = kwargs.pop("compute_metrics", None)
|
||||||
data_collator = kwargs.pop("data_collator", None)
|
data_collator = kwargs.pop("data_collator", None)
|
||||||
optimizers = kwargs.pop("optimizers", (None, None))
|
optimizers = kwargs.pop("optimizers", (None, None))
|
||||||
output_dir = kwargs.pop("output_dir", "./regression")
|
|
||||||
preprocess_logits_for_metrics = kwargs.pop("preprocess_logits_for_metrics", None)
|
preprocess_logits_for_metrics = kwargs.pop("preprocess_logits_for_metrics", None)
|
||||||
|
kwargs.pop("output_dir") # remove output_dir from kwargs
|
||||||
args = RegressionTrainingArguments(output_dir, a=a, b=b, keep_report_to=keep_report_to, **kwargs)
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = RegressionTrainingArguments(tmp_dir, a=a, b=b, keep_report_to=keep_report_to, **kwargs)
|
||||||
return Trainer(
|
return Trainer(
|
||||||
model,
|
model,
|
||||||
args,
|
args,
|
||||||
@ -713,7 +713,8 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
|
|
||||||
# Base training. Should have the same results as test_reproducible_training
|
# Base training. Should have the same results as test_reproducible_training
|
||||||
model = RegressionModel()
|
model = RegressionModel()
|
||||||
args = TrainingArguments("./regression", learning_rate=0.1, report_to="none")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, learning_rate=0.1, report_to="none")
|
||||||
trainer = Trainer(model, args, train_dataset=train_dataset)
|
trainer = Trainer(model, args, train_dataset=train_dataset)
|
||||||
trainer.train()
|
trainer.train()
|
||||||
self.check_trained_model(trainer.model)
|
self.check_trained_model(trainer.model)
|
||||||
@ -735,7 +736,8 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
|
|
||||||
def test_model_init(self):
|
def test_model_init(self):
|
||||||
train_dataset = RegressionDataset()
|
train_dataset = RegressionDataset()
|
||||||
args = TrainingArguments("./regression", learning_rate=0.1, report_to="none")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, learning_rate=0.1, report_to="none")
|
||||||
trainer = Trainer(args=args, train_dataset=train_dataset, model_init=lambda: RegressionModel())
|
trainer = Trainer(args=args, train_dataset=train_dataset, model_init=lambda: RegressionModel())
|
||||||
trainer.train()
|
trainer.train()
|
||||||
self.check_trained_model(trainer.model)
|
self.check_trained_model(trainer.model)
|
||||||
@ -782,8 +784,9 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
"disable_tqdm": True,
|
"disable_tqdm": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./generation",
|
tmp_dir,
|
||||||
**args_kwargs,
|
**args_kwargs,
|
||||||
)
|
)
|
||||||
trainer = Trainer(
|
trainer = Trainer(
|
||||||
@ -797,8 +800,9 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
trainer.train()
|
trainer.train()
|
||||||
|
|
||||||
grad_accum_loss_callback = StoreLossCallback()
|
grad_accum_loss_callback = StoreLossCallback()
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./generation",
|
tmp_dir,
|
||||||
**args_kwargs,
|
**args_kwargs,
|
||||||
gradient_accumulation_steps=2,
|
gradient_accumulation_steps=2,
|
||||||
per_device_train_batch_size=4,
|
per_device_train_batch_size=4,
|
||||||
@ -879,8 +883,9 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
"disable_tqdm": True,
|
"disable_tqdm": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./generation",
|
tmp_dir,
|
||||||
**args_kwargs,
|
**args_kwargs,
|
||||||
)
|
)
|
||||||
trainer = Trainer(
|
trainer = Trainer(
|
||||||
@ -894,8 +899,9 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
trainer.train()
|
trainer.train()
|
||||||
|
|
||||||
grad_accum_loss_callback = StoreLossCallback()
|
grad_accum_loss_callback = StoreLossCallback()
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./generation",
|
tmp_dir,
|
||||||
**args_kwargs,
|
**args_kwargs,
|
||||||
gradient_accumulation_steps=2,
|
gradient_accumulation_steps=2,
|
||||||
per_device_train_batch_size=4,
|
per_device_train_batch_size=4,
|
||||||
@ -987,7 +993,8 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
|
|
||||||
def test_custom_optimizer(self):
|
def test_custom_optimizer(self):
|
||||||
train_dataset = RegressionDataset()
|
train_dataset = RegressionDataset()
|
||||||
args = TrainingArguments("./regression", report_to="none")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, report_to="none")
|
||||||
model = RegressionModel()
|
model = RegressionModel()
|
||||||
optimizer = torch.optim.SGD(model.parameters(), lr=1.0)
|
optimizer = torch.optim.SGD(model.parameters(), lr=1.0)
|
||||||
lr_scheduler = torch.optim.lr_scheduler.LambdaLR(optimizer, lr_lambda=lambda x: 1.0)
|
lr_scheduler = torch.optim.lr_scheduler.LambdaLR(optimizer, lr_lambda=lambda x: 1.0)
|
||||||
@ -1005,8 +1012,9 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
model = RegressionModel()
|
model = RegressionModel()
|
||||||
num_steps, num_warmup_steps = 10, 2
|
num_steps, num_warmup_steps = 10, 2
|
||||||
extra_kwargs = {"power": 5.0, "lr_end": 1e-5} # Non-default arguments
|
extra_kwargs = {"power": 5.0, "lr_end": 1e-5} # Non-default arguments
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./regression",
|
tmp_dir,
|
||||||
lr_scheduler_type="polynomial",
|
lr_scheduler_type="polynomial",
|
||||||
lr_scheduler_kwargs=extra_kwargs,
|
lr_scheduler_kwargs=extra_kwargs,
|
||||||
learning_rate=0.2,
|
learning_rate=0.2,
|
||||||
@ -1032,8 +1040,9 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
model = RegressionModel()
|
model = RegressionModel()
|
||||||
num_steps, num_warmup_steps = 10, 2
|
num_steps, num_warmup_steps = 10, 2
|
||||||
extra_kwargs = {"min_lr": 1e-5} # Non-default arguments
|
extra_kwargs = {"min_lr": 1e-5} # Non-default arguments
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./regression",
|
tmp_dir,
|
||||||
lr_scheduler_type="cosine_with_min_lr",
|
lr_scheduler_type="cosine_with_min_lr",
|
||||||
lr_scheduler_kwargs=extra_kwargs,
|
lr_scheduler_kwargs=extra_kwargs,
|
||||||
learning_rate=0.2,
|
learning_rate=0.2,
|
||||||
@ -1055,8 +1064,9 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
# test passed arguments for a custom ReduceLROnPlateau scheduler
|
# test passed arguments for a custom ReduceLROnPlateau scheduler
|
||||||
train_dataset = RegressionDataset(length=64)
|
train_dataset = RegressionDataset(length=64)
|
||||||
eval_dataset = RegressionDataset(length=64)
|
eval_dataset = RegressionDataset(length=64)
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./regression",
|
tmp_dir,
|
||||||
eval_strategy="epoch",
|
eval_strategy="epoch",
|
||||||
metric_for_best_model="eval_loss",
|
metric_for_best_model="eval_loss",
|
||||||
report_to="none",
|
report_to="none",
|
||||||
@ -1087,8 +1097,9 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
train_dataset = RegressionDataset(length=64)
|
train_dataset = RegressionDataset(length=64)
|
||||||
eval_dataset = RegressionDataset(length=64)
|
eval_dataset = RegressionDataset(length=64)
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./regression",
|
tmp_dir,
|
||||||
lr_scheduler_type="reduce_lr_on_plateau",
|
lr_scheduler_type="reduce_lr_on_plateau",
|
||||||
eval_strategy="epoch",
|
eval_strategy="epoch",
|
||||||
metric_for_best_model="eval_loss",
|
metric_for_best_model="eval_loss",
|
||||||
@ -1127,7 +1138,8 @@ class TrainerIntegrationPrerunTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
from transformers.optimization import Adafactor, AdafactorSchedule
|
from transformers.optimization import Adafactor, AdafactorSchedule
|
||||||
|
|
||||||
train_dataset = RegressionDataset()
|
train_dataset = RegressionDataset()
|
||||||
args = TrainingArguments("./regression", report_to="none")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, report_to="none")
|
||||||
model = RegressionModel()
|
model = RegressionModel()
|
||||||
optimizer = Adafactor(model.parameters(), scale_parameter=True, relative_step=True, warmup_init=True, lr=None)
|
optimizer = Adafactor(model.parameters(), scale_parameter=True, relative_step=True, warmup_init=True, lr=None)
|
||||||
lr_scheduler = AdafactorSchedule(optimizer)
|
lr_scheduler = AdafactorSchedule(optimizer)
|
||||||
@ -1179,7 +1191,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
train_dataset = RegressionDataset()
|
train_dataset = RegressionDataset()
|
||||||
eval_dataset = RegressionDataset()
|
eval_dataset = RegressionDataset()
|
||||||
model = RegressionDictModel()
|
model = RegressionDictModel()
|
||||||
args = TrainingArguments("./regression", report_to="none")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, report_to="none")
|
||||||
trainer = Trainer(model, args, train_dataset=train_dataset, eval_dataset=eval_dataset)
|
trainer = Trainer(model, args, train_dataset=train_dataset, eval_dataset=eval_dataset)
|
||||||
trainer.train()
|
trainer.train()
|
||||||
_ = trainer.evaluate()
|
_ = trainer.evaluate()
|
||||||
@ -1190,7 +1203,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
tiny_gpt2 = GPT2LMHeadModel(config)
|
tiny_gpt2 = GPT2LMHeadModel(config)
|
||||||
x = torch.randint(0, 100, (128,))
|
x = torch.randint(0, 100, (128,))
|
||||||
eval_dataset = RepeatDataset(x)
|
eval_dataset = RepeatDataset(x)
|
||||||
args = TrainingArguments("./test", report_to="none")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, report_to="none")
|
||||||
trainer = Trainer(tiny_gpt2, args, eval_dataset=eval_dataset)
|
trainer = Trainer(tiny_gpt2, args, eval_dataset=eval_dataset)
|
||||||
# By default the past_key_values are removed
|
# By default the past_key_values are removed
|
||||||
result = trainer.predict(eval_dataset)
|
result = trainer.predict(eval_dataset)
|
||||||
@ -1203,7 +1217,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
def test_training_arguments_are_left_untouched(self):
|
def test_training_arguments_are_left_untouched(self):
|
||||||
trainer = get_regression_trainer()
|
trainer = get_regression_trainer()
|
||||||
trainer.train()
|
trainer.train()
|
||||||
args = TrainingArguments("./regression", report_to=[])
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, report_to=[])
|
||||||
dict1, dict2 = args.to_dict(), trainer.args.to_dict()
|
dict1, dict2 = args.to_dict(), trainer.args.to_dict()
|
||||||
for key in dict1.keys():
|
for key in dict1.keys():
|
||||||
# Logging dir can be slightly different as they default to something with the time.
|
# Logging dir can be slightly different as they default to something with the time.
|
||||||
@ -1450,8 +1465,9 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
train_dataset = RepeatDataset(x)
|
train_dataset = RepeatDataset(x)
|
||||||
|
|
||||||
# Trainer without inf/nan filter
|
# Trainer without inf/nan filter
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./test",
|
tmp_dir,
|
||||||
learning_rate=1e-9,
|
learning_rate=1e-9,
|
||||||
logging_steps=5,
|
logging_steps=5,
|
||||||
logging_nan_inf_filter=False,
|
logging_nan_inf_filter=False,
|
||||||
@ -1472,8 +1488,9 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
# redefine the model
|
# redefine the model
|
||||||
tiny_gpt2 = GPT2LMHeadModel(config)
|
tiny_gpt2 = GPT2LMHeadModel(config)
|
||||||
# Trainer without inf/nan filter
|
# Trainer without inf/nan filter
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./test",
|
tmp_dir,
|
||||||
learning_rate=1e-9,
|
learning_rate=1e-9,
|
||||||
logging_steps=5,
|
logging_steps=5,
|
||||||
logging_nan_inf_filter=False,
|
logging_nan_inf_filter=False,
|
||||||
@ -1504,16 +1521,18 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
train_dataset = RepeatDataset(x)
|
train_dataset = RepeatDataset(x)
|
||||||
|
|
||||||
# Trainer without inf/nan filter
|
# Trainer without inf/nan filter
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./test", learning_rate=1e9, logging_steps=5, logging_nan_inf_filter=False, report_to="none"
|
tmp_dir, learning_rate=1e9, logging_steps=5, logging_nan_inf_filter=False, report_to="none"
|
||||||
)
|
)
|
||||||
trainer = Trainer(tiny_gpt2, args, train_dataset=train_dataset)
|
trainer = Trainer(tiny_gpt2, args, train_dataset=train_dataset)
|
||||||
trainer.train()
|
trainer.train()
|
||||||
log_history_no_filter = trainer.state.log_history
|
log_history_no_filter = trainer.state.log_history
|
||||||
|
|
||||||
# Trainer with inf/nan filter
|
# Trainer with inf/nan filter
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./test", learning_rate=1e9, logging_steps=5, logging_nan_inf_filter=True, report_to="none"
|
tmp_dir, learning_rate=1e9, logging_steps=5, logging_nan_inf_filter=True, report_to="none"
|
||||||
)
|
)
|
||||||
trainer = Trainer(tiny_gpt2, args, train_dataset=train_dataset)
|
trainer = Trainer(tiny_gpt2, args, train_dataset=train_dataset)
|
||||||
trainer.train()
|
trainer.train()
|
||||||
@ -1576,7 +1595,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
train_dataset = RegressionDataset()
|
train_dataset = RegressionDataset()
|
||||||
config = GPT2Config(vocab_size=100, n_positions=128, n_embd=32, n_layer=3, n_head=4)
|
config = GPT2Config(vocab_size=100, n_positions=128, n_embd=32, n_layer=3, n_head=4)
|
||||||
tiny_gpt2 = GPT2LMHeadModel(config)
|
tiny_gpt2 = GPT2LMHeadModel(config)
|
||||||
args = TrainingArguments("./test", report_to="none", dataloader_persistent_workers=False)
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, report_to="none", dataloader_persistent_workers=False)
|
||||||
|
|
||||||
# Single evaluation dataset
|
# Single evaluation dataset
|
||||||
eval_dataset = RegressionDataset()
|
eval_dataset = RegressionDataset()
|
||||||
@ -1619,8 +1639,9 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
train_dataset = RegressionDataset()
|
train_dataset = RegressionDataset()
|
||||||
config = GPT2Config(vocab_size=100, n_positions=128, n_embd=32, n_layer=3, n_head=4)
|
config = GPT2Config(vocab_size=100, n_positions=128, n_embd=32, n_layer=3, n_head=4)
|
||||||
tiny_gpt2 = GPT2LMHeadModel(config)
|
tiny_gpt2 = GPT2LMHeadModel(config)
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./test",
|
tmp_dir,
|
||||||
report_to="none",
|
report_to="none",
|
||||||
dataloader_persistent_workers=True,
|
dataloader_persistent_workers=True,
|
||||||
dataloader_num_workers=2,
|
dataloader_num_workers=2,
|
||||||
@ -1678,8 +1699,9 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
self.assertNotEqual(modeling_llama.apply_rotary_pos_emb, liger_rotary_pos_emb)
|
self.assertNotEqual(modeling_llama.apply_rotary_pos_emb, liger_rotary_pos_emb)
|
||||||
self.assertFalse(isinstance(tiny_llama.model.norm, LigerRMSNorm))
|
self.assertFalse(isinstance(tiny_llama.model.norm, LigerRMSNorm))
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./test",
|
tmp_dir,
|
||||||
use_liger_kernel=True,
|
use_liger_kernel=True,
|
||||||
)
|
)
|
||||||
Trainer(tiny_llama, args)
|
Trainer(tiny_llama, args)
|
||||||
@ -2162,8 +2184,9 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
# Make the Trainer believe it's a parallelized model
|
# Make the Trainer believe it's a parallelized model
|
||||||
model.is_parallelizable = True
|
model.is_parallelizable = True
|
||||||
model.model_parallel = True
|
model.model_parallel = True
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
args = TrainingArguments(
|
args = TrainingArguments(
|
||||||
"./regression", per_device_train_batch_size=16, per_device_eval_batch_size=16, report_to="none"
|
tmp_dir, per_device_train_batch_size=16, per_device_eval_batch_size=16, report_to="none"
|
||||||
)
|
)
|
||||||
trainer = Trainer(model, args, train_dataset=RegressionDataset(), eval_dataset=RegressionDataset())
|
trainer = Trainer(model, args, train_dataset=RegressionDataset(), eval_dataset=RegressionDataset())
|
||||||
# Check the Trainer was fooled
|
# Check the Trainer was fooled
|
||||||
@ -2518,7 +2541,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
def test_dynamic_shapes(self):
|
def test_dynamic_shapes(self):
|
||||||
eval_dataset = DynamicShapesDataset(batch_size=self.batch_size)
|
eval_dataset = DynamicShapesDataset(batch_size=self.batch_size)
|
||||||
model = RegressionModel(a=2, b=1)
|
model = RegressionModel(a=2, b=1)
|
||||||
args = TrainingArguments("./regression", report_to="none")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, report_to="none")
|
||||||
trainer = Trainer(model, args, eval_dataset=eval_dataset)
|
trainer = Trainer(model, args, eval_dataset=eval_dataset)
|
||||||
|
|
||||||
# Check evaluation can run to completion
|
# Check evaluation can run to completion
|
||||||
@ -2535,7 +2559,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
self.assertTrue(np.all(seen[expected.shape[0] :] == -100))
|
self.assertTrue(np.all(seen[expected.shape[0] :] == -100))
|
||||||
|
|
||||||
# Same tests with eval accumulation
|
# Same tests with eval accumulation
|
||||||
args = TrainingArguments("./regression", eval_accumulation_steps=2, report_to="none")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, eval_accumulation_steps=2, report_to="none")
|
||||||
trainer = Trainer(model, args, eval_dataset=eval_dataset)
|
trainer = Trainer(model, args, eval_dataset=eval_dataset)
|
||||||
|
|
||||||
# Check evaluation can run to completion
|
# Check evaluation can run to completion
|
||||||
@ -3185,7 +3210,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
)
|
)
|
||||||
eval_dataset = GlueDataset(data_args, tokenizer=tokenizer, mode="dev")
|
eval_dataset = GlueDataset(data_args, tokenizer=tokenizer, mode="dev")
|
||||||
|
|
||||||
training_args = TrainingArguments(output_dir="./examples", use_cpu=True, report_to="none")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
training_args = TrainingArguments(output_dir=tmp_dir, use_cpu=True, report_to="none")
|
||||||
trainer = Trainer(model=model, args=training_args, eval_dataset=eval_dataset)
|
trainer = Trainer(model=model, args=training_args, eval_dataset=eval_dataset)
|
||||||
result = trainer.evaluate()
|
result = trainer.evaluate()
|
||||||
self.assertLess(result["eval_loss"], 0.2)
|
self.assertLess(result["eval_loss"], 0.2)
|
||||||
@ -3202,8 +3228,9 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
)
|
)
|
||||||
for example in dataset.examples:
|
for example in dataset.examples:
|
||||||
example["labels"] = example["input_ids"]
|
example["labels"] = example["input_ids"]
|
||||||
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
training_args = TrainingArguments(
|
training_args = TrainingArguments(
|
||||||
output_dir="./examples",
|
output_dir=tmp_dir,
|
||||||
use_cpu=True,
|
use_cpu=True,
|
||||||
per_device_eval_batch_size=1,
|
per_device_eval_batch_size=1,
|
||||||
report_to="none",
|
report_to="none",
|
||||||
@ -3237,7 +3264,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
# Adding one column not used by the model should have no impact
|
# Adding one column not used by the model should have no impact
|
||||||
train_dataset = SampleIterableDataset(label_names=["labels", "extra"])
|
train_dataset = SampleIterableDataset(label_names=["labels", "extra"])
|
||||||
|
|
||||||
args = RegressionTrainingArguments(output_dir="./examples", max_steps=4)
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = RegressionTrainingArguments(output_dir=tmp_dir, max_steps=4)
|
||||||
trainer = Trainer(model=model, args=args, train_dataset=train_dataset)
|
trainer = Trainer(model=model, args=args, train_dataset=train_dataset)
|
||||||
trainer.train()
|
trainer.train()
|
||||||
self.assertEqual(trainer.state.global_step, 4)
|
self.assertEqual(trainer.state.global_step, 4)
|
||||||
@ -3252,7 +3280,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
# Adding one column not used by the model should have no impact
|
# Adding one column not used by the model should have no impact
|
||||||
eval_dataset = SampleIterableDataset(label_names=["labels", "extra"])
|
eval_dataset = SampleIterableDataset(label_names=["labels", "extra"])
|
||||||
|
|
||||||
args = RegressionTrainingArguments(output_dir="./examples")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = RegressionTrainingArguments(output_dir=tmp_dir)
|
||||||
trainer = Trainer(model=model, args=args, eval_dataset=eval_dataset, compute_metrics=AlmostAccuracy())
|
trainer = Trainer(model=model, args=args, eval_dataset=eval_dataset, compute_metrics=AlmostAccuracy())
|
||||||
results = trainer.evaluate()
|
results = trainer.evaluate()
|
||||||
|
|
||||||
@ -3279,7 +3308,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
model = RegressionPreTrainedModel(config)
|
model = RegressionPreTrainedModel(config)
|
||||||
eval_dataset = SampleIterableDataset()
|
eval_dataset = SampleIterableDataset()
|
||||||
|
|
||||||
args = RegressionTrainingArguments(output_dir="./examples")
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = RegressionTrainingArguments(output_dir=tmp_dir)
|
||||||
trainer = Trainer(model=model, args=args, eval_dataset=eval_dataset, compute_metrics=AlmostAccuracy())
|
trainer = Trainer(model=model, args=args, eval_dataset=eval_dataset, compute_metrics=AlmostAccuracy())
|
||||||
|
|
||||||
preds = trainer.predict(trainer.eval_dataset).predictions
|
preds = trainer.predict(trainer.eval_dataset).predictions
|
||||||
@ -4052,7 +4082,8 @@ class TrainerIntegrationTest(TestCasePlus, TrainerIntegrationCommon):
|
|||||||
train_dataset = RegressionDataset()
|
train_dataset = RegressionDataset()
|
||||||
eval_dataset = RegressionDataset()
|
eval_dataset = RegressionDataset()
|
||||||
model = RegressionDictModel()
|
model = RegressionDictModel()
|
||||||
args = TrainingArguments("./regression", report_to="none", eval_use_gather_object=True)
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||||
|
args = TrainingArguments(tmp_dir, report_to="none", eval_use_gather_object=True)
|
||||||
trainer = Trainer(model, args, train_dataset=train_dataset, eval_dataset=eval_dataset)
|
trainer = Trainer(model, args, train_dataset=train_dataset, eval_dataset=eval_dataset)
|
||||||
trainer.train()
|
trainer.train()
|
||||||
_ = trainer.evaluate()
|
_ = trainer.evaluate()
|
||||||
|
Loading…
Reference in New Issue
Block a user