Skip to content

Commit f66ba3f

Browse files
Ziliang Zhaofacebook-github-bot
authored andcommitted
Make dict update fx compatible (#2766)
Summary: Pull Request resolved: #2766 Dict's `update` method cannot be supported by *fx*: ``` NotImplementedError: 'immutable_dict' object does not support mutation. If you are attempting to modify the kwargs or args of a torch.fx.Node object, ``` It needs to be handled for every key-value pair. Not 100% sure why this issue was not surfaced before. But likely it is because we have never published a model with more than one MPZCH-powered embedding table, so the code path was not hit before. Reviewed By: beekbin Differential Revision: D70227971 fbshipit-source-id: 71ef081eb68fa7c3d91d1e3431bd88bc6673285c
1 parent 5ee179c commit f66ba3f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

torchrec/modules/mc_modules.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ def apply_mc_method_to_jt_dict(
4040
def _update(
4141
base: Optional[Dict[str, JaggedTensor]], delta: Dict[str, JaggedTensor]
4242
) -> Dict[str, JaggedTensor]:
43-
if base is None:
44-
base = delta
45-
else:
46-
base.update(delta)
47-
return base
43+
res: Dict[str, JaggedTensor] = {}
44+
if base is not None:
45+
for k, v in base.items():
46+
res[k] = v
47+
for k, v in delta.items():
48+
res[k] = v
49+
return res
4850

4951

5052
@torch.fx.wrap

0 commit comments

Comments
 (0)