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

Added offloading support FP8 attention #1131

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Changes from 3 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
9 changes: 7 additions & 2 deletions transformer_engine/pytorch/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -5637,16 +5637,21 @@ def forward(
out_save = out_ret
fp8_tensors = (None, None, None, None, None, None)

ctx.fp8 = fp8 and int(os.getenv("NVTE_FP8_DPA_BWD", "1"))

from .cpu_offload import CPUOffloadEnabled

if CPUOffloadEnabled:
tensor_list = [q, k, v, out_save, cu_seqlens_q, cu_seqlens_kv]
if ctx.fp8:
tensor_list = fp8_tensors.extend(aux_ctx_tensors)
else:
tensor_list = [q, k, v, out_save].extend(aux_ctx_tensors)

qkv_layout = "sbhd_sbhd_sbhd"
for tensor in tensor_list:
if tensor is not None:
tensor.activation_offloading = True

ctx.fp8 = fp8 and int(os.getenv("NVTE_FP8_DPA_BWD", "1"))
qkvo_tensors = (q, k, v, out_save) if not ctx.fp8 else (None, None, None, None)
ctx.save_for_backward(
*qkvo_tensors,
Expand Down
Loading