mirror of
https://github.com/microsoft/autogen.git
synced 2025-09-13 10:16:06 +00:00

* Refactor into automl subpackage Moved some of the packages into an automl subpackage to tidy before the task-based refactor. This is in response to discussions with the group and a comment on the first task-based PR. Only changes here are moving subpackages and modules into the new automl, fixing imports to work with this structure and fixing some dependencies in setup.py. * Fix doc building post automl subpackage refactor * Fix broken links in website post automl subpackage refactor * Fix broken links in website post automl subpackage refactor * Remove vw from test deps as this is breaking the build * Move default back to the top-level I'd moved this to automl as that's where it's used internally, but had missed that this is actually part of the public interface so makes sense to live where it was. * Re-add top level modules with deprecation warnings flaml.data, flaml.ml and flaml.model are re-added to the top level, being re-exported from flaml.automl for backwards compatability. Adding a deprecation warning so that we can have a planned removal later. * Fix model.py line-endings * Pin pytorch-lightning to less than 1.8.0 We're seeing strange lightning related bugs from pytorch-forecasting since the release of lightning 1.8.0. Going to try constraining this to see if we have a fix. * Fix the lightning version pin Was optimistic with setting it in the 1.7.x range, but that isn't compatible with python 3.6 * Remove lightning version pin * Revert dependency version changes * Minor change to retrigger the build * Fix line endings in ml.py and model.py Co-authored-by: Qingyun Wu <qingyun.wu@psu.edu> Co-authored-by: EgorKraevTransferwise <egor.kraev@transferwise.com>
99 lines
3.2 KiB
Python
99 lines
3.2 KiB
Python
import os
|
|
|
|
try:
|
|
from transformers import Seq2SeqTrainer
|
|
except ImportError:
|
|
Seq2SeqTrainer = object
|
|
|
|
|
|
class TrainerForAuto(Seq2SeqTrainer):
|
|
def predict(
|
|
self,
|
|
test_dataset,
|
|
ignore_keys=None,
|
|
metric_key_prefix=None,
|
|
max_length=None,
|
|
num_beams=None,
|
|
):
|
|
if getattr(self, "_is_seq2seq", None):
|
|
return super().predict(
|
|
test_dataset,
|
|
ignore_keys,
|
|
metric_key_prefix=metric_key_prefix,
|
|
max_length=max_length,
|
|
num_beams=num_beams,
|
|
)
|
|
else:
|
|
return super(Seq2SeqTrainer, self).predict(
|
|
test_dataset, ignore_keys, metric_key_prefix
|
|
)
|
|
|
|
def prediction_step(
|
|
self,
|
|
model,
|
|
inputs,
|
|
prediction_loss_only,
|
|
ignore_keys,
|
|
):
|
|
if getattr(self, "_is_seq2seq", None):
|
|
return super().prediction_step(
|
|
model, inputs, prediction_loss_only, ignore_keys
|
|
)
|
|
else:
|
|
return super(Seq2SeqTrainer, self).prediction_step(
|
|
model, inputs, prediction_loss_only, ignore_keys
|
|
)
|
|
|
|
def log(self, logs) -> None:
|
|
if getattr(self, "_is_seq2seq", None):
|
|
super().log(logs)
|
|
else:
|
|
super(Seq2SeqTrainer, self).log(logs)
|
|
if not hasattr(self, "intermediate_results"):
|
|
self.intermediate_results = {}
|
|
|
|
epoch_num = logs.get("epoch", None)
|
|
if epoch_num:
|
|
self.intermediate_results.setdefault(epoch_num, {})
|
|
self.intermediate_results[epoch_num].update(logs)
|
|
|
|
def evaluate(
|
|
self,
|
|
eval_dataset=None,
|
|
ignore_keys=None,
|
|
metric_key_prefix="eval",
|
|
):
|
|
"""Overriding transformers.Trainer.evaluate by saving metrics and checkpoint path."""
|
|
from transformers.trainer_utils import PREFIX_CHECKPOINT_DIR
|
|
|
|
ckpt_dir = os.path.join(
|
|
self.args.output_dir, f"{PREFIX_CHECKPOINT_DIR}-{self.state.global_step}"
|
|
)
|
|
eval_dataset = eval_dataset if eval_dataset is not None else self.eval_dataset
|
|
|
|
# TODO: if your task is seq2seq (i.e., SUMMARIZATION), uncomment the code below (add indentation before metrics = eval_dataset...
|
|
|
|
if getattr(self, "_is_seq2seq", None):
|
|
metrics = eval_dataset and super().evaluate(
|
|
eval_dataset,
|
|
ignore_keys,
|
|
metric_key_prefix,
|
|
max_length=self.args.generation_max_length,
|
|
num_beams=self.args.generation_num_beams,
|
|
)
|
|
else:
|
|
metrics = eval_dataset and super(Seq2SeqTrainer, self).evaluate(
|
|
eval_dataset,
|
|
ignore_keys,
|
|
metric_key_prefix,
|
|
)
|
|
if hasattr(self, "ckpt_to_global_step"):
|
|
self.ckpt_to_global_step[ckpt_dir] = self.state.global_step
|
|
if metrics:
|
|
self.ckpt_to_metric[ckpt_dir] = metrics
|
|
else:
|
|
self.ckpt_to_global_step = {ckpt_dir: self.state.global_step}
|
|
self.ckpt_to_metric = {ckpt_dir: metrics} if metrics else {}
|
|
|
|
return metrics
|