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

Add fix for CPU Inference #385

Merged
merged 1 commit into from
Oct 31, 2023
Merged

Conversation

vivekkhandelwal1
Copy link
Contributor

Signed-Off By: Vivek Khandelwal vivek@nod-labs.com

@vivekkhandelwal1
Copy link
Contributor Author

@fxmarty, need your review on this.

Copy link

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Thanks! I think you don't need to hardcode the dtype - wdyt?

auto_gptq/nn_modules/qlinear/qlinear_cuda.py Outdated Show resolved Hide resolved
auto_gptq/nn_modules/qlinear/qlinear_cuda.py Outdated Show resolved Hide resolved
auto_gptq/nn_modules/qlinear/qlinear_cuda_old.py Outdated Show resolved Hide resolved
auto_gptq/nn_modules/qlinear/qlinear_cuda_old.py Outdated Show resolved Hide resolved
@fxmarty
Copy link
Collaborator

fxmarty commented Oct 30, 2023

A safe approach would be to modify https://github.com/PanQiWei/AutoGPTQ/blob/518617b8d682aaa95796f622d788e014ee882869/auto_gptq/modeling/_utils.py#L70 to pass the dtype to QuantLinear init, and to default to fp16 (ugly, but for backward compatibility).

This may not work for transformers integration though - maybe torch.get_default_dtype() would do.

@vivekkhandelwal1
Copy link
Contributor Author

@fxmarty, can you please review it now? I think we need to make the changes here https://github.com/huggingface/optimum/blob/8e7588b09df2f15c47e9b92f81ec2b05f7ae6957/optimum/gptq/quantizer.py#L242-L246 as well?

vivekkhandelwal1 added a commit to vivekkhandelwal1/optimum that referenced this pull request Oct 31, 2023
Refer: AutoGPTQ/AutoGPTQ#385

Signed-Off By: Vivek Khandelwal <vivek@nod-labs.com>
@vivekkhandelwal1
Copy link
Contributor Author

I have added a PR here: huggingface/optimum#1496

Copy link
Collaborator

@fxmarty fxmarty left a comment

Choose a reason for hiding this comment

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

LGTM, can you make sure the tests pass?

CUDA_VISIBLE_DEVICES=0 pytest tests/ -s -vvvvv

auto_gptq/nn_modules/qlinear/qlinear_cuda.py Outdated Show resolved Hide resolved
auto_gptq/nn_modules/qlinear/qlinear_cuda.py Outdated Show resolved Hide resolved
auto_gptq/nn_modules/qlinear/qlinear_cuda.py Outdated Show resolved Hide resolved
auto_gptq/nn_modules/qlinear/qlinear_cuda.py Outdated Show resolved Hide resolved
auto_gptq/nn_modules/qlinear/qlinear_cuda_old.py Outdated Show resolved Hide resolved
vivekkhandelwal1 added a commit to vivekkhandelwal1/optimum that referenced this pull request Oct 31, 2023
Refer: AutoGPTQ/AutoGPTQ#385

Signed-Off By: Vivek Khandelwal <vivek@nod-labs.com>
@vivekkhandelwal1
Copy link
Contributor Author

@fxmarty I have updated the PR with the required changes.

Copy link
Collaborator

@fxmarty fxmarty left a comment

Choose a reason for hiding this comment

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

LGTM!

Could you confirm that tests pass?

@vivekkhandelwal1
Copy link
Contributor Author

vivekkhandelwal1 commented Oct 31, 2023

CUDA_VISIBLE_DEVICES=0 pytest tests/ -s -vvvvv

The following 2 tests failed:

FAILED tests/test_q4.py::TestsQ4CUDA::test_cuda_old_0 - AssertionError: False is not true
FAILED tests/test_q4.py::TestsQ4CUDA::test_cuda_old_1 - AssertionError: False is not true

Edit:

_________________________________________________________________________________ TestsQ4CUDA.test_cuda_old_0 _________________________________________________________________________________

a = (<tests.test_q4.TestsQ4CUDA testMethod=test_cuda_old_0>,), kw = {}

    @wraps(func)
    def standalone_func(*a, **kw):
>       return func(*(a + p.args), **p.kwargs, **kw)

../shark-vivekkhandelwal1/shark.venv/lib/python3.11/site-packages/parameterized/parameterized.py:620: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_q4.py:356: in test_cuda_old
    self.assertTrue(linear.autogptq_cuda_available)
E   AssertionError: False is not true
_________________________________________________________________________________ TestsQ4CUDA.test_cuda_old_1 _________________________________________________________________________________

a = (<tests.test_q4.TestsQ4CUDA testMethod=test_cuda_old_1>,), kw = {}

    @wraps(func)
    def standalone_func(*a, **kw):
>       return func(*(a + p.args), **p.kwargs, **kw)

../shark-vivekkhandelwal1/shark.venv/lib/python3.11/site-packages/parameterized/parameterized.py:620: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_q4.py:356: in test_cuda_old
    self.assertTrue(linear.autogptq_cuda_available)
E   AssertionError: False is not true

@vivekkhandelwal1
Copy link
Contributor Author

The above failure doesn't seem to be occurring because of the changes made in this PR. @fxmarty

@fxmarty
Copy link
Collaborator

fxmarty commented Oct 31, 2023

Yes it was fixed by #387. Thank you!

@fxmarty fxmarty merged commit 878cbb0 into AutoGPTQ:main Oct 31, 2023
fxmarty pushed a commit to huggingface/optimum that referenced this pull request Oct 31, 2023
Refer: AutoGPTQ/AutoGPTQ#385

Signed-Off By: Vivek Khandelwal <vivek@nod-labs.com>
@vivekkhandelwal1
Copy link
Contributor Author

Thanks, @fxmarty, for your support in getting these patches in.

@vivekkhandelwal1 vivekkhandelwal1 deleted the gptq-fix branch October 31, 2023 11:51
out = torch.matmul(x.to(weights.dtype), weights)
out = out.half().reshape(out_shape)
out = torch.matmul(x, weights)
out = out.to(dtype=weights.dtype).reshape(out_shape)
Copy link

Choose a reason for hiding this comment

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

This seems broken in master at the moment:

File "/opt/miniconda3/envs/text-gen-gptq/lib/python3.10/site-packages/auto_gptq/nn_modules/qlinear/qlinear_cuda.py", line 272, in forward
out = out.to(dtype=weights.dtype).reshape(out_shape)
UnboundLocalError: local variable 'weights' referenced before assignment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @chuyqa, thanks for pointing out this issue. I have added a fix here: #390.

vivekkhandelwal1 added a commit to vivekkhandelwal1/AutoGPTQ that referenced this pull request Nov 1, 2023
Fixes: AutoGPTQ#385 (comment)

Signed-Off By: Vivek Khandelwal <vivek@nod-labs.com>
@SunMarc SunMarc mentioned this pull request Nov 1, 2023
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.

None yet

4 participants