From 5c60069931a2fd43d4accc6b2524fbc2565394e7 Mon Sep 17 00:00:00 2001 From: Hu Shenwei Date: Thu, 17 Jul 2025 15:47:28 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix(rules.py):=20=E7=B2=BE=E5=BA=A6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=8Cfused=5Fbias=5Fact=20=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E7=9A=84=E5=AE=9E=E7=8E=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../5_accuracy/accuracy_gpu_error.txt | 20 ------ tester/base.py | 1 + tester/paddle_to_torch/rules.py | 66 +++++++++++-------- 3 files changed, 40 insertions(+), 47 deletions(-) diff --git a/tester/api_config/5_accuracy/accuracy_gpu_error.txt b/tester/api_config/5_accuracy/accuracy_gpu_error.txt index dea2e5376..e400b14cc 100644 --- a/tester/api_config/5_accuracy/accuracy_gpu_error.txt +++ b/tester/api_config/5_accuracy/accuracy_gpu_error.txt @@ -2280,26 +2280,6 @@ paddle.einsum("mixy,bmxy,kmxy->bixy", Tensor([32, 32, 1, 1],"float32"), Tensor([ paddle.gammaln(Tensor([10, 20, 1],"float32"), ) paddle.gammaln(Tensor([2, 3, 4, 5],"float32"), ) paddle.gammaln(Tensor([2, 3, 4, 5],"float64"), ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009313154732808471, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009654839523136616, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009928022045642138, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0010831302497535944, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0010981468949466944, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0014022786635905504, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.001479289960116148, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0016999575309455395, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009313154732808471, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009654839523136616, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009928022045642138, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0010831302497535944, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0010981468949466944, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0014022786635905504, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.001479289960116148, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0016999575309455395, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(x=Tensor([2, 20, 10],"int32"), bias=Tensor([10],"float16"), dequant_scales=Tensor([10],"float32"), act_method="gelu", compute_dtype="fp16", ) -paddle.incubate.nn.functional.fused_bias_act(x=Tensor([2, 20, 512],"int32"), bias=Tensor([512],"float16"), dequant_scales=Tensor([512],"float32"), shift=Tensor([256],"float16"), smooth=Tensor([256],"float16"), act_method="geglu", compute_dtype="fp16", quant_scale=0.5, quant_round_type=1, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(x=Tensor([2, 20, 512],"int32"), bias=Tensor([512],"float16"), dequant_scales=Tensor([512],"float32"), shift=Tensor([512],"float16"), smooth=Tensor([512],"float16"), act_method="gelu", compute_dtype="fp16", quant_scale=0.5, quant_round_type=1, quant_max_bound=127.0, quant_min_bound=-127.0, ) -paddle.incubate.nn.functional.fused_bias_act(x=Tensor([2, 20, 512],"int32"), bias=Tensor([512],"float32"), dequant_scales=Tensor([512],"float32"), shift=Tensor([512],"float32"), smooth=Tensor([512],"float32"), act_method="gelu", compute_dtype="fp32", quant_scale=0.5, quant_round_type=1, quant_max_bound=127.0, quant_min_bound=-127.0, ) paddle.incubate.nn.functional.fused_layer_norm(Tensor([1, 64],"float16"), norm_weight=None, norm_bias=None, epsilon=1e-06, begin_norm_axis=1, bias=None, residual=Tensor([1, 64],"float16"), ) paddle.incubate.nn.functional.fused_layer_norm(Tensor([100, 512],"float16"), norm_weight=None, norm_bias=None, epsilon=1e-05, begin_norm_axis=1, bias=None, residual=Tensor([100, 512],"float16"), ) paddle.incubate.nn.functional.fused_layer_norm(Tensor([101, 64],"float16"), norm_weight=None, norm_bias=None, epsilon=1e-05, begin_norm_axis=1, bias=Tensor([64],"float16"), residual=Tensor([101, 64],"float16"), ) diff --git a/tester/base.py b/tester/base.py index 59caac646..5ca1b1e9b 100644 --- a/tester/base.py +++ b/tester/base.py @@ -594,6 +594,7 @@ def get_arg(api_config, arg_pos, arg_name, default=None): # some accuracy error can be considered tolerable special_accuracy_atol_rtol = { # "API": (atol, rtol), + "paddle.incubate.nn.functional.fused_bias_act": (127, 1e-2) } torch_error_skip = frozenset( diff --git a/tester/paddle_to_torch/rules.py b/tester/paddle_to_torch/rules.py index 7d579ae97..895c043ad 100644 --- a/tester/paddle_to_torch/rules.py +++ b/tester/paddle_to_torch/rules.py @@ -1866,6 +1866,26 @@ def fused_bias_act( ) -> torch.Tensor: import torch.nn.functional as F + def quant_helper_func(input, scale, round_type, max_bound, min_bound): + quant_value = max_bound * scale * input + + if round_type == 0: + quant_value = torch.round(quant_value) + else: + quant_value = torch.where(quant_value >= 0, torch.ceil(quant_value - 0.5), torch.floor(quant_value + 0.5)) + + quant_value = torch.clamp(quant_value, min=min_bound, max=max_bound) + + return quant_value + + def swiglu(x): + x, gate = x.chunk(2, dim=-1) + return x * torch.sigmoid(x) * gate + + def geglu(x): + x, gate = x.chunk(2, dim=-1) + return F.gelu(x) * gate + if compute_dtype != 'default': if compute_dtype == 'fp16': compute_dtype = 'float16' @@ -1877,30 +1897,14 @@ def fused_bias_act( x = x.to(getattr(torch, compute_dtype)) else: x = x.float() if not x.is_floating_point() else x + if dequant_scales is not None: dequant_scales = dequant_scales.to(x.dtype) x = x * dequant_scales + if bias is not None: bias = bias.to(x.dtype) x = x + bias - if shift is not None: - repeat_factor = x.shape[-1] // shift.shape[-1] - shift = shift.repeat(repeat_factor) - shift = shift.to(x.dtype) - x = x + shift - if smooth is not None: - repeat_factor = x.shape[-1] // smooth.shape[-1] - smooth = smooth.repeat(repeat_factor) - smooth = smooth.to(x.dtype) - x = x * smooth - - def swiglu(x): - x, gate = x.chunk(2, dim=-1) - return x * torch.sigmoid(x) * gate - - def geglu(x): - x, gate = x.chunk(2, dim=-1) - return F.gelu(x) * gate act_method = act_method.lower() if act_method == 'gelu': @@ -1917,17 +1921,25 @@ def geglu(x): x = geglu(x) else: raise ValueError(f"Unsupported activation method: {act_method}") + + if shift is not None: + repeat_factor = x.shape[-1] // shift.shape[-1] + shift = shift.repeat(repeat_factor) + shift = shift.to(x.dtype) + x = x + shift + + if smooth is not None: + repeat_factor = x.shape[-1] // smooth.shape[-1] + smooth = smooth.repeat(repeat_factor) + smooth = smooth.to(x.dtype) + x = x * smooth if quant_scale > 0: - x = x / quant_scale - if quant_round_type == 0: - x = torch.round(x) # Round to nearest, ties to even - elif quant_round_type == 1: - x = torch.where(x >= 0, torch.ceil(x - 0.5), torch.floor(x + 0.5)) - else: - raise ValueError(f"Unsupported quant_round_type: {quant_round_type}") - x = x * quant_scale - x = torch.clamp(x, min=quant_min_bound, max=quant_max_bound) + x = quant_helper_func(x, quant_scale, quant_round_type, quant_max_bound, quant_min_bound) + print("after quant", x) + + x = x.to(getattr(torch, "int8")) + return x """ core = "result = fused_bias_act(**kwargs)" From 85f355d932bcd21432349cb5e244fa1f41b16c30 Mon Sep 17 00:00:00 2001 From: Hu Shenwei Date: Thu, 17 Jul 2025 17:57:11 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix(rules.py):=20=E7=B2=BE=E5=BA=A6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=8Cfused=5Fbias=5Fact=20=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E7=9A=84=E5=AE=9E=E7=8E=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../5_accuracy/accuracy_gpu_error.txt | 20 +++++++++++++++++++ tester/base.py | 2 +- tester/paddle_to_torch/rules.py | 9 ++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/tester/api_config/5_accuracy/accuracy_gpu_error.txt b/tester/api_config/5_accuracy/accuracy_gpu_error.txt index e400b14cc..dea2e5376 100644 --- a/tester/api_config/5_accuracy/accuracy_gpu_error.txt +++ b/tester/api_config/5_accuracy/accuracy_gpu_error.txt @@ -2280,6 +2280,26 @@ paddle.einsum("mixy,bmxy,kmxy->bixy", Tensor([32, 32, 1, 1],"float32"), Tensor([ paddle.gammaln(Tensor([10, 20, 1],"float32"), ) paddle.gammaln(Tensor([2, 3, 4, 5],"float32"), ) paddle.gammaln(Tensor([2, 3, 4, 5],"float64"), ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009313154732808471, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009654839523136616, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009928022045642138, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0010831302497535944, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0010981468949466944, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0014022786635905504, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.001479289960116148, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([2, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0016999575309455395, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009313154732808471, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009654839523136616, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0009928022045642138, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0010831302497535944, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0010981468949466944, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0014022786635905504, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.001479289960116148, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(Tensor([464, 22016],"int32"), None, act_method="swiglu", compute_dtype="fp16", dequant_scales=Tensor([22016],"float32"), shift=None, smooth=None, quant_scale=0.0016999575309455395, quant_round_type=0, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(x=Tensor([2, 20, 10],"int32"), bias=Tensor([10],"float16"), dequant_scales=Tensor([10],"float32"), act_method="gelu", compute_dtype="fp16", ) +paddle.incubate.nn.functional.fused_bias_act(x=Tensor([2, 20, 512],"int32"), bias=Tensor([512],"float16"), dequant_scales=Tensor([512],"float32"), shift=Tensor([256],"float16"), smooth=Tensor([256],"float16"), act_method="geglu", compute_dtype="fp16", quant_scale=0.5, quant_round_type=1, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(x=Tensor([2, 20, 512],"int32"), bias=Tensor([512],"float16"), dequant_scales=Tensor([512],"float32"), shift=Tensor([512],"float16"), smooth=Tensor([512],"float16"), act_method="gelu", compute_dtype="fp16", quant_scale=0.5, quant_round_type=1, quant_max_bound=127.0, quant_min_bound=-127.0, ) +paddle.incubate.nn.functional.fused_bias_act(x=Tensor([2, 20, 512],"int32"), bias=Tensor([512],"float32"), dequant_scales=Tensor([512],"float32"), shift=Tensor([512],"float32"), smooth=Tensor([512],"float32"), act_method="gelu", compute_dtype="fp32", quant_scale=0.5, quant_round_type=1, quant_max_bound=127.0, quant_min_bound=-127.0, ) paddle.incubate.nn.functional.fused_layer_norm(Tensor([1, 64],"float16"), norm_weight=None, norm_bias=None, epsilon=1e-06, begin_norm_axis=1, bias=None, residual=Tensor([1, 64],"float16"), ) paddle.incubate.nn.functional.fused_layer_norm(Tensor([100, 512],"float16"), norm_weight=None, norm_bias=None, epsilon=1e-05, begin_norm_axis=1, bias=None, residual=Tensor([100, 512],"float16"), ) paddle.incubate.nn.functional.fused_layer_norm(Tensor([101, 64],"float16"), norm_weight=None, norm_bias=None, epsilon=1e-05, begin_norm_axis=1, bias=Tensor([64],"float16"), residual=Tensor([101, 64],"float16"), ) diff --git a/tester/base.py b/tester/base.py index 5ca1b1e9b..55557ea44 100644 --- a/tester/base.py +++ b/tester/base.py @@ -594,7 +594,7 @@ def get_arg(api_config, arg_pos, arg_name, default=None): # some accuracy error can be considered tolerable special_accuracy_atol_rtol = { # "API": (atol, rtol), - "paddle.incubate.nn.functional.fused_bias_act": (127, 1e-2) + "paddle.incubate.nn.functional.fused_bias_act": (1, 1e-2) } torch_error_skip = frozenset( diff --git a/tester/paddle_to_torch/rules.py b/tester/paddle_to_torch/rules.py index 895c043ad..105828f76 100644 --- a/tester/paddle_to_torch/rules.py +++ b/tester/paddle_to_torch/rules.py @@ -1885,6 +1885,9 @@ def swiglu(x): def geglu(x): x, gate = x.chunk(2, dim=-1) return F.gelu(x) * gate + + if dequant_scales is not None: + x = x * dequant_scales if compute_dtype != 'default': if compute_dtype == 'fp16': @@ -1897,11 +1900,7 @@ def geglu(x): x = x.to(getattr(torch, compute_dtype)) else: x = x.float() if not x.is_floating_point() else x - - if dequant_scales is not None: - dequant_scales = dequant_scales.to(x.dtype) - x = x * dequant_scales - + if bias is not None: bias = bias.to(x.dtype) x = x + bias From fd801c6490fff5471f71b784ea09782201fad347 Mon Sep 17 00:00:00 2001 From: Hu Shenwei Date: Thu, 17 Jul 2025 19:55:31 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix(rules.py):=20=E7=B2=BE=E5=BA=A6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=8Cfused=5Fbias=5Fact=20=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E7=9A=84=E5=AE=9E=E7=8E=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tester/paddle_to_torch/rules.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/tester/paddle_to_torch/rules.py b/tester/paddle_to_torch/rules.py index 105828f76..66c7e3392 100644 --- a/tester/paddle_to_torch/rules.py +++ b/tester/paddle_to_torch/rules.py @@ -1866,18 +1866,6 @@ def fused_bias_act( ) -> torch.Tensor: import torch.nn.functional as F - def quant_helper_func(input, scale, round_type, max_bound, min_bound): - quant_value = max_bound * scale * input - - if round_type == 0: - quant_value = torch.round(quant_value) - else: - quant_value = torch.where(quant_value >= 0, torch.ceil(quant_value - 0.5), torch.floor(quant_value + 0.5)) - - quant_value = torch.clamp(quant_value, min=min_bound, max=max_bound) - - return quant_value - def swiglu(x): x, gate = x.chunk(2, dim=-1) return x * torch.sigmoid(x) * gate @@ -1934,10 +1922,14 @@ def geglu(x): x = x * smooth if quant_scale > 0: - x = quant_helper_func(x, quant_scale, quant_round_type, quant_max_bound, quant_min_bound) - print("after quant", x) + x = quant_max_bound * quant_scale * x + if quant_round_type == 0: + x = torch.round(x) + else: + x = torch.where(x >= 0, torch.ceil(x - 0.5), torch.floor(x + 0.5)) + x = torch.clamp(x, min=quant_min_bound, max=quant_max_bound) - x = x.to(getattr(torch, "int8")) + x = x.to(torch.int8) return x """ From d5be285f4074a6ac29fa4c91f1655c8e45298675 Mon Sep 17 00:00:00 2001 From: Hu Shenwei Date: Thu, 17 Jul 2025 19:58:01 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix(rules.py):=20=E7=B2=BE=E5=BA=A6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=8Cfused=5Fbias=5Fact=20=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E7=9A=84=E5=AE=9E=E7=8E=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tester/paddle_to_torch/rules.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tester/paddle_to_torch/rules.py b/tester/paddle_to_torch/rules.py index 66c7e3392..93809a9d4 100644 --- a/tester/paddle_to_torch/rules.py +++ b/tester/paddle_to_torch/rules.py @@ -1925,8 +1925,10 @@ def geglu(x): x = quant_max_bound * quant_scale * x if quant_round_type == 0: x = torch.round(x) - else: + else if quant_round_type == 1: x = torch.where(x >= 0, torch.ceil(x - 0.5), torch.floor(x + 0.5)) + else: + raise ValueError(f"Unsupported quant_round_type: {quant_round_type}") x = torch.clamp(x, min=quant_min_bound, max=quant_max_bound) x = x.to(torch.int8) From d34e66015a991d88c629232927b01114d39e395b Mon Sep 17 00:00:00 2001 From: Hu Shenwei Date: Thu, 17 Jul 2025 19:59:21 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix(rules.py):=20=E7=B2=BE=E5=BA=A6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=8Cfused=5Fbias=5Fact=20=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E7=9A=84=E5=AE=9E=E7=8E=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tester/paddle_to_torch/rules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tester/paddle_to_torch/rules.py b/tester/paddle_to_torch/rules.py index 93809a9d4..d97bc1af7 100644 --- a/tester/paddle_to_torch/rules.py +++ b/tester/paddle_to_torch/rules.py @@ -1925,7 +1925,7 @@ def geglu(x): x = quant_max_bound * quant_scale * x if quant_round_type == 0: x = torch.round(x) - else if quant_round_type == 1: + elif quant_round_type == 1: x = torch.where(x >= 0, torch.ceil(x - 0.5), torch.floor(x + 0.5)) else: raise ValueError(f"Unsupported quant_round_type: {quant_round_type}")