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

test: Add torch.compile(adamw.step, ThunderCompiler()) #1456

Closed
wants to merge 1 commit into from
Closed
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
34 changes: 34 additions & 0 deletions thunder/tests/test_inplace_functionalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
from thunder.tests.opinfos import opinfos, OpInfo, make_number, SampleInput
from thunder.tests.make_tensor import make_tensor, make_tensor_like
from thunder.tests.litgpt_model import GPT, Config
from thunder.torch import _torch_to_thunder_function_map, _inplace_to_out_of_place

if TYPE_CHECKING:
Expand Down Expand Up @@ -812,3 +813,36 @@ def f_copy(a):
expected = f(x_ref)
torch.testing.assert_close(actual, expected)
torch.testing.assert_close(x, x_ref)


@instantiate(
dtypes=(dtypes.float32,),
executors=(TorchCompileExecutor,),
)
def test_adamw_with_pythia14m(executor, device, _):
config = Config.from_name("pythia-14m")
model = GPT(config).to(device=device)

params = list(model.parameters())
adamw = torch.optim.AdamW(params)
ref_params = [p.clone().detach() for p in params]
ref_adamw = torch.optim.AdamW(ref_params)

jitted_step = torch.compile(adamw.step, backend=thunder.dynamo.ThunderCompiler())

with torch.no_grad():
for p, ref_p in zip(params, ref_params):
grad = make_tensor_like(p)
p.grad = grad
ref_p.grad = grad.clone().detach()

for i in range(3):
if i > 0:
with torch.no_grad():
for p, ref_p in zip(params, ref_params):
p.grad.copy_(make_tensor_like(p))
ref_p.grad.copy_(p.grad)
jitted_step()
ref_adamw.step()

torch.testing.assert_close(ref_params, params)
Loading