Skip to content

Proxy for a Dict is not a Mapping #583

@Zilinghan

Description

@Zilinghan
from torch import nn
from typing import Mapping
from proxystore.store import Store, get_store
from proxystore.connectors.redis import RedisConnector

store = Store(
    'my-store',
    RedisConnector(hostname='localhost', port=6379),
    register=True,
)

store = get_store('my-store')  

# Define a test model 
model = nn.Sequential(
    nn.Conv2d(1, 20, 5),
    nn.ReLU(),
    nn.Conv2d(20, 64, 5),
    nn.ReLU()
)

state_dict = model.state_dict()
print(isinstance(state_dict, Mapping))                  # True
state_dict_proxy = store.proxy(state_dict)
print(isinstance(state_dict_proxy, type(state_dict)))   # True
print(isinstance(state_dict_proxy, Mapping))            # False
model.load_state_dict(state_dict_proxy)                 # Error

For a python dictionary, when I create a proxy for that, isinstance(state_dict_proxy, Mapping) gives False. As a result, I cannot use model.load_state_dict(state_dict_proxy), which has the above assertion to load the model parameters and gives the following error

Traceback (most recent call last):
  File "<path>/proxy.py", line 27, in <module>
    model.load_state_dict(state_dict_proxy)
  File "<path>/module.py", line 1994, in load_state_dict
    raise TypeError("Expected state_dict to be dict-like, got {}.".format(type(state_dict)))
TypeError: Expected state_dict to be dict-like, got <class 'Proxy'>.

Metadata

Metadata

Assignees

Labels

bugError, flaw, or fault that causes unexpected behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions