Refactor display device name / Fix tokenize_data from OpusMtEnESTransformer#353
Merged
Conversation
dd9f46f to
804c2d6
Compare
cristian-tamblay
approved these changes
Nov 7, 2025
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.
This pull request refactors how device selection (CPU/GPU) is handled across several Hugging Face model classes in the backend. The main improvement is centralizing device enumeration and mapping logic into a new utility module, which simplifies device handling and ensures consistency. Additionally, the device selection in model initialization is now more robust, and the translation model's data tokenization logic is improved for clarity and correctness.
Device handling refactor:
utils.pythat centralizes device enumeration, placeholder, and mapping logic (DEVICE_ENUM,DEVICE_PLACEHOLDER,NAME_TO_DEVICE) for CPU and available GPUs, using human-readable names for GPUs.stable_diffusion_v1_depth_controlnet.py,stable_diffusion_v2_model.py, andstable_diffusion_v3_model.pyto import device constants and mappings from the new utility module, removing redundant device code from each file. [1] [2] [3] [4]Model initialization improvements:
NAME_TO_DEVICEmapping, ensuring correct device assignment regardless of user input format. [1] [2] [3] [4]Translation model tokenization fix:
tokenize_datamethod inOpusMtEnESTransformerto handle cases where target data (y) is missing more cleanly, and improved the logic for constructing tokenized samples.Documentation update:
OpusMtEnESTransformerSchemato clarify that selecting GPU will use all available GPUs.