rwth-i6 / pytorch-to-returnn

Make PyTorch code runnable within RETURNN
3 stars 6 forks source link

allow dict/list inputs #52

Closed vieting closed 3 years ago

vieting commented 3 years ago

This PR makes it possible to use dicts or lists of tensors as input to the PyTorch models that should be converted. It was already possible to have them as input/output of a forward function (see the new test_dict_in_forward which already passes without the suggested modifications). Now, it is also possible to have them as the initial input to the model.

vieting commented 3 years ago

Many issues where you should use nest instead.

Thanks for the hint, I'll check that and update accordingly.

But more general: I don't understand, why does the model_func need this? The model_func is just intended as a simple wrapper to test the conversion. For nothing more. You don't really need this. Or why do you need this?

E.g. the module in here has a dict as input. In order to convert it, I create a model_func in which I load the module and forward the inputs to the model_function through the module. Therefore I need the dict as input. Or do you have an easier way?

albertz commented 3 years ago

E.g. the module in here has a dict as input. In order to convert it, I create a model_func in which I load the module and forward the inputs to the model_function through the module. Therefore I need the dict as input. Or do you have an easier way?

The model_func is just for testing. It is not meant to wrap a module. It just needs the numpy array for the test, nothing else.

See this example. It even loads a custom dict from a config file and passes it to the module. But the model_func function just gets the numpy array, nothing else.

vieting commented 3 years ago

Yes, I think you're right. This is probably not necessary.