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

[AudioLM] Graph break: call_method UserDefinedObjectVariable(dict) get [TorchVariable(<class 'torch.Tensor'>), ConstantVariable(NoneType)] #121345

Open
ezyang opened this issue Mar 6, 2024 · 5 comments
Labels
dynamo-triage-june2024 empathy-day Label for issues from user empathy days module: dynamo module: graph breaks oncall: pt2 triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@ezyang
Copy link
Contributor

ezyang commented Mar 6, 2024

🐛 Describe the bug

Discovered while compiling lucidrains/audiolm-pytorch

[2024-03-06 11:44:09,519] [15/0] torch._dynamo.symbolic_convert.__graph_breaks: [DEBUG] Graph break: call_method UserDefinedObjectVariable(dict) get [TorchVariable(<class 'torch.Tensor'>), ConstantVariable(NoneType)] {} from user code at:
[2024-03-06 11:44:09,519] [15/0] torch._dynamo.symbolic_convert.__graph_breaks: [DEBUG]   File "/home/ezyang/local/miniconda3-test/envs/audiolm/lib/python3.10/site-packages/einops-0.7.0-py3.10.egg/einops/packing.py", line 141, in resume_in_unpack
[2024-03-06 11:44:09,519] [15/0] torch._dynamo.symbolic_convert.__graph_breaks: [DEBUG]     backend = get_backend(tensor)
[2024-03-06 11:44:09,519] [15/0] torch._dynamo.symbolic_convert.__graph_breaks: [DEBUG]   File "/home/ezyang/local/miniconda3-test/envs/audiolm/lib/python3.10/site-packages/einops-0.7.0-py3.10.egg/einops/_backends.py", line 28, in get_backend
[2024-03-06 11:44:09,519] [15/0] torch._dynamo.symbolic_convert.__graph_breaks: [DEBUG]     _result = _type2backend.get(_type, None)

This is a bit concerning; if it's actually a dict, we should have wrapped it in UserDefinedObjectVariable. This lookup is happening in einops which had some problems

Full repro code: gist.github.com/ezyang/64c24c9fc5529f3afed4ee4266f6adc5

Versions

main

cc @msaroufim @bdhirsh @anijain2305 @zou3519 @chauhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng

@ezyang
Copy link
Contributor Author

ezyang commented Mar 6, 2024

Looking over the einops code, it looks like this is a normal dict:

_loaded_backends: dict = {}
_type2backend: dict = {}
_debug_importing = False


def get_backend(tensor) -> "AbstractBackend":
    """
    Takes a correct backend (e.g. numpy backend if tensor is numpy.ndarray) for a tensor.
    If needed, imports package and creates backend
    """
    _type = type(tensor)
    _result = _type2backend.get(_type, None)
    if _result is not None:
        return _result

    for framework_name, backend in list(_loaded_backends.items()):
        if backend.is_appropriate_type(tensor):
            _type2backend[_type] = backend
            return backend

@Skylion007
Copy link
Collaborator

I am having some similar problems with nested dicts right now. Except it's even worse as it's leading to an uncaught assestion in the constants.py (passing a Dict that should have been a ConstDict).

@yanboliang
Copy link
Contributor

yanboliang commented Mar 7, 2024

@Skylion007 Do you have a small repro for your issue? I think we should find out the scenario that a regular is not wrapped as ConstDict, then it's not hard to fix it imo.

@ezyang
Copy link
Contributor Author

ezyang commented Mar 7, 2024

If we just add allocation stack traces to all variable trackers this will be easy to nail. If someone gives me a patch I can run it on AudioLM

@williamwen42 williamwen42 added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: dynamo module: graph breaks labels Mar 8, 2024
@yanboliang yanboliang added the empathy-day Label for issues from user empathy days label Mar 11, 2024
@lezcano
Copy link
Collaborator

lezcano commented Mar 12, 2024

Dictionaries in dynamo have some limitations. The good part of the story is that these limitations are documented and it's super easy to extend our implementation to support more types!

# [Adding a new supported class within the keys of ConstDictVarialble]
# - Add its tracker type to is_hashable
# - (perhaps) Define how it is compared in _HashableTracker._eq_impl

At the moment we are graph-breaking when hitting elements of dicts that are not hashable internally:

if not is_hashable(vt):
unimplemented(f"Dict key of type {type(vt)}. Key: {vt}")

We could throw a hard error saying "this dict key is not supported, please file a ticket with your error to ask for support for this type of keys".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dynamo-triage-june2024 empathy-day Label for issues from user empathy days module: dynamo module: graph breaks oncall: pt2 triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

7 participants