Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
578d06e
Refactor connection to autograd with new joint trace creation
beverlylytle May 20, 2025
b04654a
apply update_fusion_call_ctx
beverlylytle May 21, 2025
0c19438
check bw for None
beverlylytle May 21, 2025
f0182ee
don't fuse get_grad
beverlylytle May 23, 2025
440bc96
group get_grads together for torch compile fusions
beverlylytle May 23, 2025
6bb4293
remove torchex impl of get_grad in favor of OpExProcessor exception
beverlylytle May 23, 2025
01dea9d
Merge branch 'main' into reautograd2
beverlylytle May 26, 2025
f45c92d
hide behind flag and clean up
beverlylytle May 26, 2025
eb32063
Xfail test_ddp_grad_bucketing
IvanYashchuk May 27, 2025
32b9675
Xfail test_limit_in_flight_allgathers with bucketing
IvanYashchuk May 27, 2025
675ea02
Xfail test_fsdp_with_no_sync_grad_accumulation
IvanYashchuk May 27, 2025
aafc899
Xfail test_fsdp_grad_parity_with_without_bucketing
IvanYashchuk May 27, 2025
9b4b252
Fix test_rematerialize_all_gather
IvanYashchuk May 27, 2025
a27f390
Restore test_torch_compile_cat_rope_single_fusion
IvanYashchuk May 27, 2025
56625f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 27, 2025
971c52e
remove extra rematerialization
beverlylytle May 27, 2025
d059353
Merge branch 'main' into reautograd2
beverlylytle May 28, 2025
9cc8c78
remove outdated change
beverlylytle May 28, 2025
67cde6e
Merge branch 'main' into reautograd2
beverlylytle Jun 3, 2025
e1308e1
clean up after merge
beverlylytle Jun 3, 2025
b73702a
more clean up
beverlylytle Jun 3, 2025
d39f270
Merge branch 'main' into reautograd2
beverlylytle Jun 3, 2025
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
Prev Previous commit
Next Next commit
don't fuse get_grad
  • Loading branch information
beverlylytle committed May 23, 2025
commit f0182eef0107df26ff4673c0b1abbead0311e96c
3 changes: 3 additions & 0 deletions thunder/core/transform_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ def cse_single_bsym(
skip_output=True,
)

if bsym.sym.id == prims.PrimIDs.GET_GRAD:
return new_bsym

# Skip appending this bsym to the new bound symbols due to its rhs being a common subexpression.
rhs = new_bsym.rhs
if (prior_bsym := rhs_to_bsym_map.get(rhs)) is not None and bsym._executor is prior_bsym._executor:
Expand Down
12 changes: 12 additions & 0 deletions thunder/executors/torchex.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def _arange_transform(


def _get_grad_transform(a: TensorProxy) -> TensorProxy:
# return a.grad
return prims.get_grad(a)


Expand All @@ -259,6 +260,7 @@ def _put_grad_transform(a: TensorProxy, val: TensorProxy) -> None:
# force that and recurse so that the symbol is not removed/no error is raised.
# This is breaking the intent of transform_for_operator_executor_execution, in that
# it is not executable. But there will be postprocessing that will make it executable.
# a.grad = val
prims.put_grad(a, val)
return None

Expand Down Expand Up @@ -2357,6 +2359,16 @@ def _shape_impl(t):
shape = ex.register_operator("shape", meta=prims.shape_meta, fn=_shape_impl)
_register_implementation(prims.shape, shape, checker=_always_executable)


# def _grad_impl(t):
# t.retain_grad()
# return t.grad


# grad = ex.register_operator("get_grad", meta=prims.get_grad, fn=_grad_impl)
# _register_implementation(prims.get_grad, grad, checker=_always_executable)


shallow_copy = ex.register_operator("shallow_copy", meta=prims.shallow_copy, fn=lambda x: x)
_register_implementation(prims.shallow_copy, shallow_copy, checker=_always_executable)

Expand Down
10 changes: 7 additions & 3 deletions thunder/transforms/autodiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ def split_into_forward_and_backward(joint_trace):
assert isinstance(fw_output, tuple)

grad_outs = [None for _ in fw_output]
output_pos = {o.name: i for i, o in enumerate(fw_output) if isinstance(o, thunder.TensorProxy)}
output_pos = {}
for i, o in enumerate(fw_output):
if isinstance(o, thunder.TensorProxy):
output_pos.setdefault(o.name, []).append(i)
# output_pos = {o.name: i for i, o in enumerate(fw_output) if isinstance(o, thunder.TensorProxy)}

# the proxies we need to compute in the forward - we start with the outputs of the forward
forward_proxy_names = {o.name for o in thunder.core.pytree.tree_iter(fw_output) if isinstance(o, thunder.Proxy)}
Expand Down Expand Up @@ -374,8 +378,8 @@ def split_into_forward_and_backward(joint_trace):
continue

# get grad is always part of the input, record the grad_out (will be part of the "cotangents" list)
if bsym.sym == prims.get_grad:
grad_outs[output_pos[bsym.args[0].name]] = bsym.output
if bsym.sym == prims.get_grad or bsym.sym.id == "get_grad":
grad_outs[output_pos[bsym.args[0].name].pop(0)] = bsym.output
continue

# copy_ updating a forward proxy is special regardless of the output
Expand Down
Loading