Skip to content

Set accumulate type to bf16 in activation quant #152

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

Merged
merged 2 commits into from
Jul 19, 2024
Merged
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
5 changes: 3 additions & 2 deletions jetstream_pt/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def forward(self, inputs):
if not self.quantize_activation:
result = F.linear(inputs, self.weight)
else:
# We have to call jax because we need to do dot(int8, int8)->int32.
# We have to call jax because we need to specify the output dtype of dot
# dot(int8, int8)->bf16.
# This semantic cannot be represented in torch. The inferred output dtype
# will be int8 in torch, causing the dot result to overflow.
result = torchjax.call_jax(
Expand All @@ -148,7 +149,7 @@ def forward(self, inputs):
self.weight,
(((2,), (1)), ((), ())),
None,
jnp.int32.dtype,
jnp.bfloat16.dtype,
)
result = result * self.weight_scaler
if self.quantize_activation:
Expand Down
Loading