Skip to content

Raise explicit error when FP8 is requested via from_config#42865

Open
dikshyantacharya wants to merge 2 commits intohuggingface:mainfrom
dikshyantacharya:fp8-from-config
Open

Raise explicit error when FP8 is requested via from_config#42865
dikshyantacharya wants to merge 2 commits intohuggingface:mainfrom
dikshyantacharya:fp8-from-config

Conversation

@dikshyantacharya
Copy link
Copy Markdown

Summary

from_config() currently ignores FP8 intent specified via quantization_config, silently falling back to FP32.
This PR makes the behavior explicit by raising a clear error instead.

What this PR does

  • Raises NotImplementedError when FP8 is requested via from_config()
  • Adds a regression test to lock in the behavior

Why

  • Prevents silent misconfiguration
  • Improves API correctness
  • Establishes a safe foundation for future FP8 support

Scope

This PR does not enable FP8 kernels or backend support.
It focuses solely on correctness and explicit behavior.

Copy link
Copy Markdown
Contributor

@MekkCyber MekkCyber left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Comment thread src/transformers/modeling_utils.py Outdated
Comment on lines +1310 to +1315
if quant_config is not None:
if quant_config.get("quant_method") == "fp8":
raise NotImplementedError(
"FP8 via `from_config()` is not yet supported. "
"FP8 models must be created via `from_pretrained()` with an FP8-capable backend."
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's make it general and not only for fp8

Comment on lines +1 to +11
import pytest

from transformers import AutoConfig, AutoModel


def test_fp8_from_config_raises():
config = AutoConfig.from_pretrained("gpt2")
config.quantization_config = {"quant_method": "fp8"}

with pytest.raises(NotImplementedError, match="FP8 via"):
AutoModel.from_config(config)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could you add the test to the quantization tests instead ?

@dikshyantacharya dikshyantacharya force-pushed the fp8-from-config branch 6 times, most recently from fd7022b to 8d39746 Compare December 15, 2025 18:16
@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: config

@github-actions
Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=42865&sha=417544

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.

2 participants