KEMBAR78
[dynamo] missing support for builtin function `dict.fromkeys(iterable, value=None, /)` · Issue #114963 · pytorch/pytorch · GitHub
Skip to content

[dynamo] missing support for builtin function dict.fromkeys(iterable, value=None, /) #114963

@XuehaiPan

Description

@XuehaiPan

🐛 Describe the bug

Reference: #114947 (comment)

Dynamo does not support dict.fromkeys(iterable, value=None, /) yet, which is a classmethod for dict.

I can temporarily replace this to:

- dict.fromkeys(iterable, value)
+ {k: value for k in iterable}

- dict.fromkeys(iterable)
+ {k: None for k in iterable}

But in general, we may need to implement a special path for it in BuiltinVariable.call_function.

The error:

torch._dynamo.exc.Unsupported: call_method BuiltinVariable(dict) fromkeys [ConstDictVariable()] {}

A minimal script to reproduce:

from collections import OrderedDict, defaultdict

import torch


def fn() -> None:
    d = dict.fromkeys(['a', 'b'])
    od = OrderedDict.fromkeys(['a', 'b'])
    dd = defaultdict.fromkeys(['a', 'b'])


comp_out = torch._dynamo.optimize(nopython=True)(fn)()

The error for statement d = dict.fromkeys(['a', 'b']):

torch._dynamo.exc.Unsupported: call_method BuiltinVariable(dict) fromkeys [ListVariable()] {}

The error for statement od = OrderedDict.fromkeys(['a', 'b']) / dd = defaultdict.fromkeys(['a', 'b']):

torch._dynamo.exc.Unsupported: call_method SkipFilesVariable() fromkeys [ListVariable()] {}

Versions

main branch

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @kadeng

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: dynamotriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions