microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.82k stars 2.94k forks source link

[Training] Implicit dependency of Python training API on 'torch' package #22070

Open nfnt opened 2 months ago

nfnt commented 2 months ago

Describe the issue

In the onnxruntime training API for Python, some packages in onnxruntime.training.optim import torch. Due to how Python package imports work, this results in a dependency of all packages in onnxruntime.training on torch. torch package sizes can be rather large and this size is problematic in some environments. It would be great to not require this package if using parts of onnxruntime that don't need it (e.g. onnxblock).

To reproduce

In a fresh virtual env run:

pip install onnxruntime-training-cpu
python -c 'import onnxruntime.training.onnxblock'

This will fail with

ModuleNotFoundError: No module named 'torch'

Urgency

Not too urgent, I have a workaround in place that's patching the API in onnxruntime.training.__init__.py to only add the optim package if torch is available.

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.19.2

PyTorch Version

not using Pytorch

Execution Provider

Default CPU

Execution Provider Library Version

No response

xadupre commented 2 months ago

cc @baijumeswani

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

nfnt commented 1 month ago

Is there anything I can help with to get this resolved? I can see that there were some CI failures on #22072, but I'm not sure if they are related to the proposed changes.