Skip to content

ORTTrainer / ORTSeq2SeqTrainer refactoring - Inference with ORTModel#189

Merged
JingyaHuang merged 31 commits into
mainfrom
refactoring-orttrainer-inf
Sep 19, 2022
Merged

ORTTrainer / ORTSeq2SeqTrainer refactoring - Inference with ORTModel#189
JingyaHuang merged 31 commits into
mainfrom
refactoring-orttrainer-inf

Conversation

@JingyaHuang
Copy link
Copy Markdown
Contributor

@JingyaHuang JingyaHuang commented May 13, 2022

What does this PR do?

This PR replaces the bare inference sessions in ORTTrainer with subclasses of ORTModel, and enables the inference with ONNX Runtime in ORTSeq2SeqTrainer.

[Refactoring ORTTrainer]

  • Replace inference session in evaluation_loop_ort and prediction_loop_ort with subclasses of ORTModel.
  • Clean up unused in evaluation_loop_ort and prediction_loop_ort

[Refactoring ORTSeq2SeqTrainer]

  • Adapt OnnxConfigWithPastAndLoss on the top of DecoderOnnxConfig.
  • Generate dummy labels and compute of loss in _DecoderWithLMhead.
  • Add labels and the loss in sequence-to-sequence ort modeling.
  • Override evaluation_loop_ort and prediction_loop_ort to leverage ORTModelForSeq2SeqLM.

@fxmarty fxmarty mentioned this pull request May 13, 2022
1 task
@JingyaHuang JingyaHuang changed the base branch from main to jingya-refactoring-ort-model July 18, 2022 12:49
@JingyaHuang JingyaHuang changed the base branch from jingya-refactoring-ort-model to main July 18, 2022 12:50
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

HuggingFaceDocBuilderDev commented Aug 22, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Copy Markdown
Contributor

@regisss regisss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great Jingya!

Copy link
Copy Markdown
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, well done @JingyaHuang 🔥

Comment thread optimum/onnxruntime/trainer.py Outdated
JingyaHuang and others added 2 commits September 7, 2022 10:22
* Override export of ORTSeq2SeqTrainer

* Do not force download by default in ORTModel (#356)

* Update OnnxConfigWithLoss wrapper

* ORT optimizer refactorization (#294)

* Refactorization of ORTOptimizer

* Refactorization of ORTModel

* Adapt examples according to refactorization

* Adapt tests

* Fix style

* Remove quantizer modification

* Fix style

* Apply modifications from #270 for quantizer and optimizer to have same behavior

* Add test for optimization of Seq2Seq models

* Fix style

* Add ort config saving when optimizing a model

* Add ort config saving when quantizing a model

* Add tests

* Fix style

* Adapt optimization examples

* Fix readme

* Remove unused parameter

* Adapt quantization examples

* Fix quantized model and ort config saving

* Add documentation

* Add model configuration saving to simplify loading of optimized model

* Fix style

* Fix description

* Fix quantization tests

* Remove opset argument which is onnx config default opset when exporting with ORTModels

* Fix import (#360)

* Fix export of decoders

* Add flag to export only decoders

* Fix ORTTrainer inference ort subclass parsing

* Fix filenames when empty suffix given (#363)

* fix(optimization): handle empty file suffix

* fix(quantization): handle empty file suffix

* use pathlibfor save_dir

* run test again

* Update optimum/onnxruntime/quantization.py

Co-authored-by: Ella Charlaix <80481427+echarlaix@users.noreply.github.com>

* ReRun test that failed because of cache (network)

Co-authored-by: Ella Charlaix <80481427+echarlaix@users.noreply.github.com>

* Override the evaluation and prediction loop in ORTSeq2SeqTrainer

* Fix documentation (#369)

* fix class

* Update optimization.mdx

* Fix label smoother device prob

* Fix lm_logits and labels dimension mismatch

* Clean up

Co-authored-by: fxmarty <9808326+fxmarty@users.noreply.github.com>
Co-authored-by: Ella Charlaix <80481427+echarlaix@users.noreply.github.com>
Co-authored-by: Pierre Snell <ierezell@gmail.com>
Co-authored-by: Pierre Snell <pierre.snell@botpress.com>
Co-authored-by: Philipp Schmid <32632186+philschmid@users.noreply.github.com>
@JingyaHuang JingyaHuang changed the title ORTTrainer refactoring - Inference with ORTModel ORTTrainer / ORTSeq2SeqTrainer refactoring - Inference with ORTModel Sep 7, 2022
Copy link
Copy Markdown
Contributor

@regisss regisss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work Jingya 🔥
I just have two naive questions

Comment thread optimum/onnxruntime/trainer.py
Comment thread optimum/onnxruntime/trainer.py
Comment thread optimum/onnx/modeling_seq2seq.py Outdated
Comment thread optimum/onnxruntime/modeling_seq2seq.py Outdated
Comment thread optimum/onnxruntime/modeling_seq2seq.py Outdated
Comment thread optimum/onnxruntime/modeling_seq2seq.py
JingyaHuang and others added 3 commits September 19, 2022 14:29
Co-authored-by: Ella Charlaix <80481427+echarlaix@users.noreply.github.com>
Co-authored-by: Ella Charlaix <80481427+echarlaix@users.noreply.github.com>
Comment thread optimum/onnxruntime/modeling_seq2seq.py Outdated
Comment thread optimum/onnxruntime/modeling_seq2seq.py Outdated
JingyaHuang and others added 3 commits September 19, 2022 17:16
Copy link
Copy Markdown
Collaborator

@echarlaix echarlaix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🔥

@JingyaHuang JingyaHuang merged commit eada157 into main Sep 19, 2022
@JingyaHuang JingyaHuang deleted the refactoring-orttrainer-inf branch September 19, 2022 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants