Skip to content

Allow for fast accumulation selection for FP8 GEMM - #3416

Merged
copybara-service[bot] merged 5 commits into
google:mainfrom
wenscarl:expm_fp8_precision
Nov 8, 2023
Merged

copybara-service[bot] merged 5 commits into
google:mainfrom
wenscarl:expm_fp8_precision

Conversation

@wenscarl

@wenscarl wenscarl commented Oct 16, 2023 •

Copy link
Copy Markdown
Contributor

In this PR, issue#6168 is addressed by introducing a custom gradients(forward mode autodiff) for fp8 dot_general. This PR is closely related to FLAX PR-6599@reedwm @kaixih @burmako

@wenscarl wenscarl changed the title Allow for fast accumulation selection for FP8 GEMM [draft]Allow for fast accumulation selection for FP8 GEMM Oct 16, 2023
@wenscarl wenscarl changed the title [draft]Allow for fast accumulation selection for FP8 GEMM Allow for fast accumulation selection for FP8 GEMM Oct 17, 2023
@burmako

burmako commented Oct 17, 2023

Copy link
Copy Markdown

Thank you for the heads up! Also cc @GleasonK

Comment thread flax/linen/fp8_ops.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't observe the usage of FWD/BWD_DTYPE in this commit. Perhaps we should limit this commit to handling accumulation datatypes exclusively. For simplicity, I suggest hardcoding the accumulation datatypes directly within the dot general custom gradient functions as we have already done for the input/output dtypes.

@wenscarl
wenscarl force-pushed the expm_fp8_precision branch 2 times, most recently from fed6f32 to ac9e8d2 Compare October 27, 2023 20:33
@codecov-commenter

codecov-commenter commented Oct 27, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #3416 (09f2ec9) into main (0b126b8) will increase coverage by 0.12%.
Report is 10 commits behind head on main.
The diff coverage is 93.33%.

@@            Coverage Diff             @@
##             main    #3416      +/-   ##
==========================================
+ Coverage   83.50%   83.63%   +0.12%     
==========================================
  Files          56       56              
  Lines        6725     6802      +77     
==========================================
+ Hits         5616     5689      +73     
- Misses       1109     1113       +4     
Files Coverage Δ
flax/linen/fp8_ops.py 98.92% <93.33%> (-1.08%) ⬇️

... and 4 files with indirect coverage changes

copybara-service Bot pushed a commit to openxla/xla that referenced this pull request Nov 2, 2023
Imported from GitHub PR #6599

FP8 cublasLt matmul uses fast accumulation when both operands' precision are DEFAULT. Otherwise fall back to high precision acuumulation. Issue##6168

This PR is closely related to Flax PR-![3416](google/flax#3416).
Copybara import of the project:

--
a4140da by shuw <[email protected]>:

Add FP8 fast accumulation support for cublasLt.

--
9684568 by shuw <[email protected]>:

Improve based on review #1

--
e906d76 by shuw <[email protected]>:

Improve based on review #2

Merging this change closes #6599

FUTURE_COPYBARA_INTEGRATE_REVIEW=#6599 from wenscarl:fp8_fast_accumulation e906d76
PiperOrigin-RevId: 578904075
copybara-service Bot pushed a commit to openxla/xla that referenced this pull request Nov 2, 2023
Imported from GitHub PR #6599

FP8 cublasLt matmul uses fast accumulation when both operands' precision are DEFAULT. Otherwise fall back to high precision acuumulation. Issue##6168

This PR is closely related to Flax PR-![3416](google/flax#3416).
Copybara import of the project:

--
a4140da by shuw <[email protected]>:

Add FP8 fast accumulation support for cublasLt.

--
9684568 by shuw <[email protected]>:

Improve based on review #1

--
e906d76 by shuw <[email protected]>:

Improve based on review #2

Merging this change closes #6599

FUTURE_COPYBARA_INTEGRATE_REVIEW=#6599 from wenscarl:fp8_fast_accumulation e906d76
PiperOrigin-RevId: 578904075
copybara-service Bot pushed a commit to openxla/xla that referenced this pull request Nov 2, 2023
Imported from GitHub PR #6599

FP8 cublasLt matmul uses fast accumulation when both operands' precision are DEFAULT. Otherwise fall back to high precision acuumulation. Issue##6168

This PR is closely related to Flax PR-![3416](google/flax#3416).
Copybara import of the project:

--
a4140da by shuw <[email protected]>:

Add FP8 fast accumulation support for cublasLt.

--
9684568 by shuw <[email protected]>:

Improve based on review #1

--
e906d76 by shuw <[email protected]>:

Improve based on review #2

Merging this change closes #6599

FUTURE_COPYBARA_INTEGRATE_REVIEW=#6599 from wenscarl:fp8_fast_accumulation e906d76
PiperOrigin-RevId: 578904075
copybara-service Bot pushed a commit to openxla/xla that referenced this pull request Nov 2, 2023
Imported from GitHub PR #6599

FP8 cublasLt matmul uses fast accumulation when both operands' precision are DEFAULT. Otherwise fall back to high precision acuumulation. Issue##6168

This PR is closely related to Flax PR-![3416](google/flax#3416).
Copybara import of the project:

--
a4140da by shuw <[email protected]>:

Add FP8 fast accumulation support for cublasLt.

--
9684568 by shuw <[email protected]>:

Improve based on review #1

--
e906d76 by shuw <[email protected]>:

Improve based on review #2

Merging this change closes #6599

COPYBARA_INTEGRATE_REVIEW=#6599 from wenscarl:fp8_fast_accumulation e906d76
PiperOrigin-RevId: 578948593
copybara-service Bot pushed a commit to tensorflow/tensorflow that referenced this pull request Nov 2, 2023
Imported from GitHub PR openxla/xla#6599

FP8 cublasLt matmul uses fast accumulation when both operands' precision are DEFAULT. Otherwise fall back to high precision acuumulation. Issue#openxla/xla#6168

This PR is closely related to Flax PR-![3416](google/flax#3416).
Copybara import of the project:

--
a4140da8ca08cd2d4796a7b8f032827867a361bc by shuw <[email protected]>:

Add FP8 fast accumulation support for cublasLt.

--
96845683cc4b1e7b947bc919fbf97d8865abeac9 by shuw <[email protected]>:

Improve based on review #1

--
e906d7620780d2cf1fe8433c933648dcb98dc61d by shuw <[email protected]>:

Improve based on review #2

Merging this change closes #6599

PiperOrigin-RevId: 578948593
@levskaya

levskaya commented Nov 2, 2023

Copy link
Copy Markdown
Collaborator

@wenscarl - sorry I was about to merge but there's a fresh merge conflict - would you mind resolving it and I can merge?

Comment thread flax/linen/fp8_ops.py Outdated

@kaixih kaixih Nov 2, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you make this have the same signature of the lax.dot_general() so that I can inject it to the jnp.einsum?

@partial(custom_jvp, nondiff_argnums=(2, 3, 4))
def dot_general_with_precision(lhs, rhs, dimension_numbers, precision=None, preferred_element_type=None):
   return lax.dot_general(lhs, rhs, dimension_numbers, precision=lax.Precision.DEFAULT)
  

Comment thread flax/linen/fp8_ops.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this also needs to be changed accordingly, like:

@dot_general_with_precision.defjvp
def dot_general_with_precision_jvp(dimension_numbers, precision, preferred_element_type, primals, tangents):

Comment thread flax/linen/fp8_ops.py Resolved
@kaixih

kaixih commented Nov 3, 2023

Copy link
Copy Markdown
Contributor

As for #3416 (comment), can you also rebase your change against the latest? I think the upstream has done some format cleanup. @wenscarl

@wenscarl
wenscarl force-pushed the expm_fp8_precision branch 2 times, most recently from d307996 to 2176aac Compare November 3, 2023 17:23
@kaixih

kaixih commented Nov 6, 2023

Copy link
Copy Markdown
Contributor

@levskaya Can you take a look if the merge can be triggered?

@levskaya

levskaya commented Nov 7, 2023

Copy link
Copy Markdown
Collaborator

Sorry could you re-push, there was a stupid warning being triggered that I've now silenced. But beyond that I'm seeing this error in internal CI for Fp8Test.test_fp8_dot_general_injection:

jax.errors.SimplifiedTraceback: For simplicity, JAX has removed its internal frames from the traceback of the following exception. Set JAX_TRACEBACK_FILTERING=off to include these.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/build/work/74f3597f42da87446d9a71de4bf7594fa9c1/google3/runfiles/google3/third_party/py/flax/tests/linen/linen_test.py", line 940, in test_fp8_dot_general_injection
    output2a, output2b = run(True, expected_shapes_new)
  File "/build/work/74f3597f42da87446d9a71de4bf7594fa9c1/google3/runfiles/google3/third_party/py/flax/tests/linen/linen_test.py", line 909, in run
    y, initial_vars = p.init_with_output(init_key, x)
  File "/build/work/74f3597f42da87446d9a71de4bf7594fa9c1/google3/runfiles/google3/third_party/py/flax/linen/linear.py", line 167, in __call__
    out = dot_general(
  File "/build/work/74f3597f42da87446d9a71de4bf7594fa9c1/google3/runfiles/google3/third_party/py/flax/linen/fp8_ops.py", line 196, in __call__
    y_qdq = dot_general_with_precision(x_qdq, k_qdq, dimension_numbers)  # type: ignore
AttributeError: No JVP defined for custom_jvp function dot_general_with_precision using defjvp.

@kaixih

kaixih commented Nov 7, 2023

Copy link
Copy Markdown
Contributor

@levskaya Could you please review this once more? We have resolved the issue with the failed test, which occurred due to the accidental deletion of a decorator in the previous commit. All tests are now passing successfully.

@copybara-service
copybara-service Bot merged commit ed98abb into google:main Nov 8, 2023
@levskaya

levskaya commented Nov 8, 2023

Copy link
Copy Markdown
Collaborator

@kaixih - should be merged now! sorry for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants