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

【PIR API adaptor No.127】llm_int8_linear #58882

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions python/paddle/nn/quant/quantized_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
from paddle import _C_ops
from paddle.base.data_feeder import check_dtype
from paddle.base.framework import convert_np_dtype_to_dtype_
from paddle.framework import LayerHelper, in_dynamic_mode
from paddle.framework import (
LayerHelper,
in_dynamic_mode,
in_dynamic_or_pir_mode,
)


def weight_quantize(x, algo="weight_only_int8"):
Expand Down Expand Up @@ -217,7 +221,7 @@ def llm_int8_linear(
... print(out.shape)
[1, 2, 32]
"""
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
out = _C_ops.llm_int8_linear(x, weight, bias, weight_scale, threshold)
return out
else:
Expand Down
8 changes: 5 additions & 3 deletions test/quantization/test_llm_int8_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from paddle.base import core
from paddle.base.framework import default_main_program
from paddle.framework import set_default_dtype
from paddle.pir_utils import test_with_pir_api

np.random.seed(123)
paddle.seed(123)
Expand Down Expand Up @@ -86,11 +87,12 @@ def get_llm_int8_linear_out(self):
)
return out.numpy()

@test_with_pir_api
def get_llm_int8_linear_out_static(self):
paddle.enable_static()
main = base.Program()
start = base.Program()
with base.program_guard(main, start):
main = base.static.Program()
start = base.static.Program()
with base.static.program_guard(main, start):
x = paddle.static.data("x", self.x.shape, dtype=self.x.dtype)

weight = paddle.static.data(
Expand Down