Skip to content

Commit

Permalink
fix for tuples with non-hashable entries (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
vieting authored Dec 7, 2022
1 parent 37a6930 commit 3d1585f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pytorch_to_returnn/import_wrapper/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@


def wrap(obj, *, name: str, ctx: WrapCtx):
def _fully_hashable(obj_):
if not isinstance(obj_, Hashable):
return False
if isinstance(obj_, tuple):
return all(_fully_hashable(elem) for elem in obj_)
return True

if isinstance(obj, (WrappedObject, WrappedModule)):
return obj
if isinstance(obj, ctx.keep_as_is_types):
return obj
if isinstance(obj, Hashable) and obj in ctx.explicit_wrapped_objects:
if _fully_hashable(obj) and obj in ctx.explicit_wrapped_objects:
func = ctx.explicit_wrapped_objects[obj]
obj = func(obj, name=name, ctx=ctx)
obj = _nested_transform(obj, lambda _x: wrap(_x, name="%s..." % name, ctx=ctx))
Expand Down

0 comments on commit 3d1585f

Please sign in to comment.