Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GPTQ, CompressedTensors] Fix unsafe imports and metada check #34815

Merged
merged 9 commits into from
Dec 24, 2024

Conversation

vasqu
Copy link
Contributor

@vasqu vasqu commented Nov 19, 2024

What does this PR do?

Fixes some unsafe imports for GPTQ and CompressedTensors as well as an unsafe metadata check for GPTQ, i.e. metadata can't be checked if the package doesn't exist...

I tried looking into integrating the env validation function before even creating the quantizers but that would require a complete restructure, especially since the env is checked after creation to get additional info like device map etc. So I kept it as simple as I could and wrapped the unsafe stuff.

Minimal reproducible script to trigger gptq errors (when optimum is not installed):

from transformers import AutoModelForCausalLM, AutoTokenizer, GPTQConfig


model_id = "facebook/opt-125m"
tokenizer = AutoTokenizer.from_pretrained(model_id)
dataset = ["auto-gptq is an easy-to-use model quantization library with user-friendly apis, based on GPTQ algorithm."]
gptq_config = GPTQConfig(bits=4, dataset=dataset, tokenizer=tokenizer)


quantized_model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", quantization_config=gptq_config)

Fixes #34765

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@SunMarc @MekkCyber

@vasqu vasqu force-pushed the fix-quant-loading branch from 3c927c3 to f3c7f78 Compare November 19, 2024 17:27
@MekkCyber MekkCyber self-requested a review November 20, 2024 11:15
@vasqu vasqu changed the title Fix quant loading for gptq and compressed tensors [GPTQ, CompressedTensors] Fix unsafe imports and metada check Nov 22, 2024
@MekkCyber
Copy link
Contributor

Thanks for the fix @vasqu, LGTM !

@MekkCyber MekkCyber requested review from SunMarc and removed request for MekkCyber November 22, 2024 11:40
Copy link
Member

@SunMarc SunMarc 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 fixes !

@SunMarc SunMarc requested a review from ArthurZucker November 22, 2024 16:13
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Looks good but I think we should always call validate_environment before even initializing the quantizer (so probably update super (HfQuantizer) to call it at init time no?

@vasqu
Copy link
Contributor Author

vasqu commented Nov 25, 2024

@ArthurZucker
See my comments above:

I tried looking into integrating the env validation function before even creating the quantizers but that would require a complete restructure, especially since the env is checked after creation to get additional info like device map etc. So I kept it as simple as I could and wrapped the unsafe stuff.

The problem is some quantizers need additional information that is not available at creation; another option I could see it to add a post_init to create those unsafe parts :)

@vasqu
Copy link
Contributor Author

vasqu commented Dec 8, 2024

gentle ping @ArthurZucker

Copy link
Collaborator

@ArthurZucker ArthurZucker 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 explaining

@ArthurZucker
Copy link
Collaborator

Not sure if it was fixed by recent quantizer compressed changes, let's resolve conflicts and good to merge

@vasqu
Copy link
Contributor Author

vasqu commented Dec 24, 2024

Forgot about this PR myself 😅 should be good to merge now! Thx for the merges here, ci sometimes do be flaky tho

@MekkCyber
Copy link
Contributor

will merge it once the ci is green @vasqu 🤗

@MekkCyber MekkCyber merged commit 24c91f0 into huggingface:main Dec 24, 2024
25 checks passed
@vasqu vasqu deleted the fix-quant-loading branch December 24, 2024 18:33
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.

ModuleNotFoundError: No module named 'optimum' when loading model in TextGenerationWebUI
5 participants