From 6e915d7a3357f9b7d8d9b06698f97602d86ba4e0 Mon Sep 17 00:00:00 2001 From: JunghwanNA <70629228+shaun0927@users.noreply.github.com> Date: Fri, 17 Apr 2026 13:09:07 +0900 Subject: [PATCH] Fix TypeError in Model.load on Python 3.9+ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit isinstance(state_dict, Dict[str, torch.Tensor]) raises "Subscripted generics cannot be used with class and instance checks" on Python 3.9+ because typing.Dict[str, torch.Tensor] is a parameterized generic and not a concrete class. Narrow the type check to the concrete dict class so the existing control flow — and the downstream ValueError for non-dict inputs — is reachable. load_state_dict already validates the dict contents (key/tensor shape), so the narrower Dict[...] check never provided additional safety. Fixes #810 --- transformers4rec/torch/model/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transformers4rec/torch/model/base.py b/transformers4rec/torch/model/base.py index 3aeb4eb3f..61427cf16 100644 --- a/transformers4rec/torch/model/base.py +++ b/transformers4rec/torch/model/base.py @@ -914,7 +914,7 @@ def load( max_sequence_length=max_sequence_length, top_k=top_k, ) - if isinstance(state_dict, Dict[str, torch.Tensor]): + if isinstance(state_dict, dict): model.load_state_dict(state_dict, strict=strict) else: raise ValueError("`state_dict` must be a dictionary of parameter (torch) tensors.")