Skip to content

Track when a particular function (like _run_ddp_forward) is in the stack #93789

@anijain2305

Description

@anijain2305

In some cases, it is useful to know if a particular frame is running under a specific context. For example, we would like to know _run_ddp_forward is ancestor of the current frame we are analyzing. This enables us to skip/specialize on this additional information during Dynamo bytecode processing.

Conceptually, it could look something like this

Before Dynamo

def fn():
    .....
    .....

After Dynamo

def wrapper(fn):
    def inner(*args, **kwargs):
        torchdyanmo.global_ctx.add("ddp_on")
        out = torchdynamo.optimize(my_compiler)(fn)(*args, **kwargs)
        torchdyanmo.global_ctx.remove("ddp_on")
        return out
    return inner

cc @ezyang @soumith @msaroufim @wconstab @ngimel @bdhirsh

Metadata

Metadata

Assignees

Labels

enhancementNot as big of a feature, but technically not a bug. Should be easy to fixoncall: pt2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions