Skip to content

fix: use dtype instead of deprecated torch_dtype - #978

Open
xyf5432 wants to merge 1 commit into
OptimalScale:mainfrom
xyf5432:fix/use-dtype-instead-of-torch-dtype
Open

fix: use dtype instead of deprecated torch_dtype#978
xyf5432 wants to merge 1 commit into
OptimalScale:mainfrom
xyf5432:fix/use-dtype-instead-of-torch-dtype

Conversation

@xyf5432

@xyf5432 xyf5432 commented Aug 28, 2026

Copy link
Copy Markdown

Summary

config.torch_dtype and the torch_dtype keyword argument were deprecated in transformers 4.56 (PR #39782) and replaced by dtype. This PR updates the AutoModelForSequenceClassification.from_pretrained call in contrib/rlhflow/reward_modeling.py (line 44) to select the keyword from the installed transformers version using packaging.version, so transformers < 4.56 keeps working.

Changes

  • contrib/rlhflow/reward_modeling.py: add a _dtype_kwargs helper that returns {"dtype": ...} on transformers >= 4.56 and {"torch_dtype": ...} otherwise; the from_pretrained call passes it as **_dtype_kwargs(torch.bfloat16).

Test

  • The modified file compiles (python -m py_compile).
  • On transformers >= 4.56 the call uses dtype and emits no deprecation warning; on older versions it passes torch_dtype unchanged.

Fixes #977

…4.56

config.torch_dtype and the torch_dtype keyword argument were deprecated in transformers 4.56 (PR #39782). Pass dtype based on the installed transformers version (packaging.version), falling back to torch_dtype on older versions.
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.

Use dtype instead of deprecated torch_dtype for transformers >= 4.56

1 participant