lhotse icon indicating copy to clipboard operation
lhotse copied to clipboard

Don't install torchaudio automatically if torch is installed

Open csukuangfj opened this issue 1 year ago • 8 comments

The following code https://github.com/lhotse-speech/lhotse/blob/08a613a06d258ab72679f0d2e952ec668afbe185/setup.py#L140-L156

installs torchaudio automatically for the user, which is.not.correct, I believe.

The reasons are:

(1) The following exception message is never seen by the user since the exception is caught by the outer except statement https://github.com/lhotse-speech/lhotse/blob/08a613a06d258ab72679f0d2e952ec668afbe185/setup.py#L148-L154

(2) The code tries to install torchaudio without specifying its version, which defaults to the latest version. However, each version of torchaudio works only with a specific version of torch. If the user is not using the latest version of torch, the installed torchaudio won't work.

csukuangfj avatar Aug 06 '22 09:08 csukuangfj

There are two possible workarounds:

(1) Just throw the exception and let the user resolve it

(2) Detect the currently installed torch version and install a version of torchaudio that is compatible with the current version of torch.

csukuangfj avatar Aug 06 '22 09:08 csukuangfj

Someone encountered this issue while building a docker image using https://github.com/k2-fsa/icefall/blob/master/docker/Ubuntu18.04-pytorch1.7.1-cuda11.0-cudnn8/Dockerfile

It has torch 1.7.1 pre-installed.

image

csukuangfj avatar Aug 06 '22 09:08 csukuangfj

I don’t understand, the outer except statement catches ImportError, but we are raising a ValueError, it should go through. I will try to confirm that later.

We should raise an error when torch is installed but torchaudio is not. It is not possible to install matching torchaudio because there are too many options (conda, pip, nightly, source, cpu version, GPU version, etc).

pzelasko avatar Aug 06 '22 11:08 pzelasko

I don’t understand, the outer except statement catches ImportError, but we are raising a ValueError, it should go through. I will try to confirm that later.

Ah, you are right. But I don't understand why it does not show the ValueError exception while building the docker image.

csukuangfj avatar Aug 06 '22 11:08 csukuangfj

Do you have the full logs from that docker build, and is the Dockerfile available somewhere?

pzelasko avatar Aug 06 '22 11:08 pzelasko

https://github.com/k2-fsa/icefall/blob/master/docker/Ubuntu18.04-pytorch1.7.1-cuda11.0-cudnn8/Dockerfile

The dockerfile is in icefall. It has been updated by https://github.com/k2-fsa/icefall/pull/524

I don't have the full logs. It is reported by someone else via WeChat.

csukuangfj avatar Aug 06 '22 12:08 csukuangfj

Please also see https://github.com/lhotse-speech/lhotse/issues/777

It does not throw an exception in #777 but tries to install a new version of torch.

csukuangfj avatar Aug 06 '22 12:08 csukuangfj

I think that the Dockerfile is missing some deps like libsndfile which makes torchaudio import fail, and Lhotse "thinks" it's not installed since it caught an ImportError...

Try to install all of the deps that Lhotse has in its CI and re-try:

https://github.com/lhotse-speech/lhotse/blob/08a613a06d258ab72679f0d2e952ec668afbe185/.github/workflows/unit_tests.yml#L45

pzelasko avatar Aug 08 '22 20:08 pzelasko