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

Remove reference cycle - with exceptions #228

Merged
merged 2 commits into from
May 12, 2022

Conversation

anijain2305
Copy link
Contributor

This is a followup of #223

#223 was cleaning up the OutputGraph. However, it was missing the cleanup when an exception was raised. This led to some memory held alive for the following case. Therefore, moving the cleanup to finalize of try ... except block.


@torchdynamo.disable
def print_mem(name):
    print(name, torch.cuda.memory_allocated() / 10**9, "GB")


def fn1(x, y, z):
    out = torch.addcdiv(x, y, z)
    print_mem("Inside func")
    return out.sum()


def fn():
    x = torch.randn(1024, 1024, 1024, device="cuda")
    y = torch.randn(1024, 1024, 1024, device="cuda")
    z = torch.randn(1024, 1024, 1024, device="cuda")
    return fn1(x, y, z)


fn()
print_mem("Outside func")
print("------ Eager Done --------")
print("\n\n\n")

# torchdynamo.config.debug = True
# torchdynamo.config.trace = True

with torchdynamo.optimize("eager"):
    fn()
    print_mem("Outside func")
print("------ TorchDynamo Done --------")
print("\n\n\n")


gc.collect()
torch.cuda.empty_cache()
print_mem("End")

@anijain2305
Copy link
Contributor Author

The first commit did not account for InliningInstructionTranslator

@anijain2305 anijain2305 merged commit fd0c103 into pytorch:main May 12, 2022
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.

3 participants