Use GPU for translation model inference and compute BLEU/TER locally with torchmetrics#709
Open
Irozuku wants to merge 2 commits into
Open
Use GPU for translation model inference and compute BLEU/TER locally with torchmetrics#709Irozuku wants to merge 2 commits into
Irozuku wants to merge 2 commits into
Conversation
639a877 to
24d1347
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes translation models not using the GPU during inference, and replaces the deprecated
evaluatelibrary withtorchmetricsfor the BLEU and TER translation metrics (CHRF already used torchmetrics).evaluate.load(...)fetches the metric script from a remote endpoint (Hugging Face Hub) on every call; switching totorchmetricscomputes the scores fully locally, with no network dependency.Type of Change
Check all that apply like this [x]:
Changes (by file)
DashAI/back/models/hugging_face/base_opus_mt_transformer.py:predict()now moves the model to CUDA whendevice == "gpu"(else CPU) and setseval()mode before inference. Previously the model stayed on CPU after init/load, so inputs were copied to a CPU device and inference never used the GPU even when selected.DashAI/back/models/hugging_face/m2m100_transformer.py: same GPU placement fix inpredict().DashAI/back/models/hugging_face/nllb_transformer.py: same GPU placement fix inpredict().DashAI/back/models/hugging_face/t5_small_transformer.py: same GPU placement fix inpredict().DashAI/back/metrics/translation/bleu.py: replacedevaluate.load("bleu")withtorchmetrics.text.bleu.BLEUScore; references wrapped as list of lists. Import ofprepare_to_metricswitched totranslation_metric.DashAI/back/metrics/translation/ter.py: replacedevaluate.load("ter")withtorchmetrics.text.ter.TranslationEditRate. Import ofprepare_to_metricswitched totranslation_metric.Testing
OpusMtEnEsTransformer) with GPU selected as the device.nvidia-smishows utilization /next(model.model.parameters()).deviceiscuda) and is faster than CPU.