How to load PyTorch weights from KNIME Hub without converting to ONNX?

I’m trying to have my Python node load some pretrained PyTorch weights hosted on a KNIME Hub server. As you know, KNIME currently has poor PyTorch support. I’m aware of people using the following workarounds, but I ran into problems with each one:

  1. Convert the PyTorch weights into ONNX format and then back again - First of all, PyTorch has poor support for converting ONNX files back into PyTorch models. Secondly, my models have many features from other deep learning libraries, that would be lost during the conversion.
  2. Use the URL to File Path (Variable) Node as suggested in this thread - this approach only applies to locally hosted files identified by a URL

  1. Fetch the weight files from the Python Node directly using a URL, i.e. using torch.hub.load_state_dict_from_url("/http/url/to/hosted/weight/files/") - I get a HTTP 403 Access Denied Error when using the https:// url, and the function doesn’t recognize a knime:// url.

  2. I successfully managed to convert a directory of PyTorch weights on the server into a table of binary objects, using the following setup. However, I’m stuck on how to convert the binary objects into PyTorch weights or models.

Screenshot 2024-01-24 151338

Hi @qzhang1,

Have you tried to transfer the files to a temporary folder under workflow data area and read them in your Python Script node?

Here are the nodes you can use:

If you are using KNIME Business Hub:

If you are using KNIME Server:

To create a temp folder:

To transfer files:

To list files and transfer them:

1 Like

Hello @armingrudd,

Thank you for your swift and helpful response! I thought about creating temp files, but wasn’t aware of the temp folder node.

I have one question however - When using that node in a remote workflow, and writing relative to the current workflow data area, are we writing to a local temp folder, or directly to the server?

1 Like

Relative to current workflow data area points to the current workflow which is executing. So, when an instance of the workflow is running on Hub, then the temp folder is also created on Hub under the running workflow’s data folder.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.