Skip to content

Commit

Permalink
dce all-const returning symbols in subsymbols (#1465)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-vi authored Nov 25, 2024
1 parent 60f3ee1 commit 81f83f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion thunder/core/transform_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ def _remove_noop_subsymbols(bsym: BoundSymbol) -> None:
for sbsym in bsym.subsymbols:
if len(sbsym.subsymbols) == 0 and not sbsym.sym.is_prim:
continue

# if all outputs are constants, we elmininate the subsymbol
if not has_tags(bsym, {prims.OpTags.DONT_DCE}) and not any(
o is not None for o in sbsym.flat_proxy_outs
): # is not None to avoid cast to bool
continue
_remove_noop_subsymbols(sbsym)
nsbsyms.append(sbsym)

Expand Down
4 changes: 4 additions & 0 deletions thunder/tests/test_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,7 @@ def test_hf_llama():
res2 = jm(past_key_values=res["past_key_values"], **args2)
expected2 = model(past_key_values=res["past_key_values"], **args2)
assert_close(res2, expected2, rtol=1e-1, atol=1e-1)

top_level_symbol_names = {bsym.sym.name for bsym in thunder.last_traces(jm)[-1].bound_symbols}
# changes this to fewer as needed, the goal is to not have too many fusions
assert len([s for s in top_level_symbol_names if s.startswith("nvFusion")]) == 7

0 comments on commit 81f83f3

Please sign in to comment.