diffsynth-engine 0.4.4.dev5__py3-none-any.whl → 0.5.1.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -72,39 +72,33 @@ def fp8_inference(enabled=True):
72
72
  ) -> torch.Tensor:
73
73
  device = input.device
74
74
  origin_dtype = input.dtype
75
- scale_a = 1.0
75
+ origin_shape = input.shape
76
+ input = input.reshape(-1, origin_shape[-1])
77
+
78
+ x_max = torch.max(torch.abs(input), dim=-1, keepdim=True).values
79
+ fp8_max = 448.0
76
80
  # For float8_e4m3fnuz, the maximum representable value is half of that of e4m3fn.
77
81
  # To avoid overflow and ensure numerical compatibility during FP8 computation,
78
82
  # we scale down the input by 2.0 in advance.
79
83
  # This scaling will be compensated later during the final result scaling.
80
84
  if DTYPE_FP8 == torch.float8_e4m3fnuz:
81
- scale_a = 2.0
82
- input = input / scale_a
85
+ fp8_max = fp8_max / 2.0
86
+ scale_a = torch.clamp(x_max / fp8_max, min=1.0).float().to(device=device)
87
+ scale_b = torch.ones((weight.shape[0], 1)).float().to(device=device)
88
+ input = input / scale_a
83
89
  input = input.to(DTYPE_FP8)
84
90
  weight = weight.to(DTYPE_FP8)
85
91
 
86
- if len(input.shape) > 2:
87
- origin_shape = input.shape
88
- input = input.reshape(-1, origin_shape[-1])
89
- result = torch._scaled_mm(
90
- input,
91
- weight.T,
92
- scale_a=torch.tensor(scale_a).to(device=device),
93
- scale_b=torch.tensor(1.0).to(device=device),
94
- bias=bias,
95
- out_dtype=origin_dtype,
96
- )
97
- new_shape = origin_shape[:-1] + result.shape[-1:]
98
- result = result.reshape(new_shape)
99
- else:
100
- result = torch._scaled_mm(
101
- input,
102
- weight.T,
103
- scale_a=torch.tensor(scale_a).to(device=device),
104
- scale_b=torch.tensor(1.0).to(device=device),
105
- bias=bias,
106
- out_dtype=origin_dtype,
107
- )
92
+ result = torch._scaled_mm(
93
+ input,
94
+ weight.T,
95
+ scale_a=scale_a,
96
+ scale_b=scale_b.T,
97
+ bias=bias,
98
+ out_dtype=origin_dtype,
99
+ )
100
+ new_shape = origin_shape[:-1] + result.shape[-1:]
101
+ result = result.reshape(new_shape)
108
102
  return result
109
103
 
110
104
  F.linear = fp8_linear
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: diffsynth_engine
3
- Version: 0.4.4.dev5
3
+ Version: 0.5.1.dev1
4
4
  Author: MuseAI x ModelScope
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Operating System :: OS Independent
@@ -166,7 +166,7 @@ diffsynth_engine/utils/constants.py,sha256=csKPtXA9YFoRPnhUBmnw3zf1KlTV963a43Nu4
166
166
  diffsynth_engine/utils/download.py,sha256=8O56zQr2taY4BnCBEKVk3YGorTqTTCqTblf7tI9otXA,6721
167
167
  diffsynth_engine/utils/env.py,sha256=43x-kBjt5zI2cwZ9G4BOeTbedi2k6TuBzHGOBeFbFvU,280
168
168
  diffsynth_engine/utils/flag.py,sha256=6zQLnoEaU69pBEyhavCgydQfP0khw5ppCU7sue4yRqg,1370
169
- diffsynth_engine/utils/fp8_linear.py,sha256=NosnWMoAr_IpFcLn-OYbAx-vXySphjxutDZqmXLNjJI,4064
169
+ diffsynth_engine/utils/fp8_linear.py,sha256=k34YFWo2dc3t8aKjHaCW9CbQMOTqXxaDHk8aw8aKif4,3857
170
170
  diffsynth_engine/utils/gguf.py,sha256=ZWvw46V4g4uVyAR_oCq-4K5nPdKVrYk3u47uXMgA9lU,14092
171
171
  diffsynth_engine/utils/image.py,sha256=xZ_bEU-DdoSwMPG7jpP1daAro2tsy9ddeXKbXqXaeC0,9335
172
172
  diffsynth_engine/utils/loader.py,sha256=Z5v1WNDWFY0OrVubB70j5VU3zeaAfEK_j8c1KrGI4yM,1240
@@ -181,8 +181,8 @@ diffsynth_engine/utils/video.py,sha256=Ne0rd2lb59UT1q5EotpjlY7OT8F9oTCFDyo1ST77u
181
181
  diffsynth_engine/utils/memory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
182
182
  diffsynth_engine/utils/memory/linear_regression.py,sha256=oW_EQEw13oPoyUrxiL8A7Ksa5AuJ2ynI2qhCbfAuZbg,3930
183
183
  diffsynth_engine/utils/memory/memory_predcit_model.py,sha256=EXprSl_zlVjgfMWNXP-iw83Ot3hyMcgYaRPv-dvyL84,3943
184
- diffsynth_engine-0.4.4.dev5.dist-info/licenses/LICENSE,sha256=x7aBqQuVI0IYnftgoTPI_A0I_rjdjPPQkjnU6N2nikM,11346
185
- diffsynth_engine-0.4.4.dev5.dist-info/METADATA,sha256=9da4omhF3UQxWXQbIf47qR8KqeGL7vhp-CvlEnhYpUA,1117
186
- diffsynth_engine-0.4.4.dev5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
187
- diffsynth_engine-0.4.4.dev5.dist-info/top_level.txt,sha256=6zgbiIzEHLbhgDKRyX0uBJOV3F6VnGGBRIQvSiYYn6w,17
188
- diffsynth_engine-0.4.4.dev5.dist-info/RECORD,,
184
+ diffsynth_engine-0.5.1.dev1.dist-info/licenses/LICENSE,sha256=x7aBqQuVI0IYnftgoTPI_A0I_rjdjPPQkjnU6N2nikM,11346
185
+ diffsynth_engine-0.5.1.dev1.dist-info/METADATA,sha256=myookCu04gVV_XbTrYo9J798-pmfmzpBernyCIl_5NQ,1117
186
+ diffsynth_engine-0.5.1.dev1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
187
+ diffsynth_engine-0.5.1.dev1.dist-info/top_level.txt,sha256=6zgbiIzEHLbhgDKRyX0uBJOV3F6VnGGBRIQvSiYYn6w,17
188
+ diffsynth_engine-0.5.1.dev1.dist-info/RECORD,,