Add torchcodec in docstrings/tests for datasets 4.0#39156
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
|
Hi @lhoestq There is slack reporting issues, but I saw many failed tests
I only add maybe I should also install something else? Could you provide a full installation steps 🙏 ? I will rerun the CI again today. It's best to verify it before merge, as we have several events like switching all jobs to A10, run with torch 2.8 etc. and they already cause quite some chaos. |
|
added the missing torchcodec installations, it should be fine now ! |
|
the examples_torch job has so maybe from Also a tiny change to fix is also necessary. (update the 1 src/transformers/models/hubert/modeling_hubert.py or src/transformers/models/hubert/modular_hubert.py) |
|
I fixed the TypeError and the modeling_hubert :) |
| ... speech, _ = sf.read(batch["file"]) | ||
| ... batch["speech"] = speech | ||
| ... decoder = AudioDecoder(batch["file"]) | ||
| ... batch["speech"] = torch.mean(decoder.get_all_samples().data, axis=0) |
There was a problem hiding this comment.
cc @eustlb since datasets is now using torchcodec I updated this part of the docs (no need to have both soundfile and torchcodec), but since torchcodec isn't available for windows users I might revert, wdyt ?
(shouldn't necessarily block this PR since the goal is to make the CI happy for datasets release, happy to revert later)
There was a problem hiding this comment.
I agree that it's better not updating the default docs until it is supported also on windows. I just realised those map_to_array everywhere are broken anyway...
There was a problem hiding this comment.
I reverted them (no torchcodec) and then I fixed them since the code docs example on main was actually broken
qubvel
left a comment
There was a problem hiding this comment.
Thanks, LGTM for object detection changes
| ENV UV_PYTHON=/usr/local/bin/python | ||
| RUN pip --no-cache-dir install uv && uv venv && uv pip install --no-cache-dir -U pip setuptools | ||
| RUN uv pip install --no-cache-dir 'torch' 'torchaudio' 'torchvision' --index-url https://download.pytorch.org/whl/cpu | ||
| RUN uv pip install --no-cache-dir 'torch' 'torchaudio' 'torchvision' 'torchcodec' --index-url https://download.pytorch.org/whl/cpu |
There was a problem hiding this comment.
should we add it to any requirements instead?
There was a problem hiding this comment.
It's also in the requirements, at examples/pytorch/_tests_requirements.txt
I assume having it in the dockerfile with the other torch-related libs is about making sure it's the CPU version that is installed
There was a problem hiding this comment.
Thanks @lhoestq! I love torchcodec! (it would be amazing in the near future to move from numpy arrays by default → torch to everything torch native?). Comments:
- can we revert doc changes? snippets for the few I tried are broken anyway, let's change to
torchcodecwhen it is not blocking for windows users - why the stereo → mono conversion in the pipeline? AFAIK it is directly handled by the models no?
| ... speech, _ = sf.read(batch["file"]) | ||
| ... batch["speech"] = speech | ||
| ... decoder = AudioDecoder(batch["file"]) | ||
| ... batch["speech"] = torch.mean(decoder.get_all_samples().data, axis=0) |
There was a problem hiding this comment.
I agree that it's better not updating the default docs until it is supported also on windows. I just realised those map_to_array everywhere are broken anyway...
| _data = torch.mean(_data, 0) if _data.ndim > 1 else _data | ||
| inputs = {"array": _data, "sampling_rate": _audio_samples.sample_rate} |
There was a problem hiding this comment.
AFAIK we do not do mono → stereo conversion here by default has it's directly handled by the model's feature extractor (eg here). Have you added it here for any reason?
sure !
oh I didn't know that, let me change it :) I was converting to mono because the {"array": ..., "sampling_rate": ...} input format was already mono so I assumed the models were also mono. |
eustlb
left a comment
There was a problem hiding this comment.
Tiny nit, otherwise LGTM! 🤗
| @@ -436,9 +436,10 @@ def forward( | |||
| input_values (`torch.FloatTensor` of shape `(batch_size, max_length, num_mel_bins)`): | |||
| Float values mel features extracted from the raw audio waveform. Raw audio waveform can be obtained by | |||
| loading a `.flac` or `.wav` audio file into an array of type `list[float]` or a `numpy.ndarray`, *e.g.* via | |||
There was a problem hiding this comment.
Can we propagate this change?
| loading a `.flac` or `.wav` audio file into an array of type `list[float]` or a `numpy.ndarray`, *e.g.* via | |
| loading a `.flac` or `.wav` audio file into an array of type `list[float]`, a `numpy.ndarray` or a `torch.Tensor`, *e.g.* via |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: audio_spectrogram_transformer, clvp, data2vec, hubert, moonshine, qwen2_5_omni, qwen2_audio, sew, sew_d, speech_encoder_decoder, speech_to_text |
) * fix dataset run_object_detection * bump version * keep same dataset actually * torchcodec in docstrings and testing utils * torchcodec in dockerfiles and requirements * remove duplicate * add torchocodec to all the remaining docker files * fix tests * support torchcodec in audio classification and ASR * [commit to revert] build ci-dev images * [commit to revert] trigger circleci * [commit to revert] build ci-dev images * fix * fix modeling_hubert * backward compatible run_object_detection * revert ci trigger commits * fix mono conversion and support torch tensor as input * revert map_to_array docs + fix it * revert mono * nit in docstring * style * fix modular --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
) * fix dataset run_object_detection * bump version * keep same dataset actually * torchcodec in docstrings and testing utils * torchcodec in dockerfiles and requirements * remove duplicate * add torchocodec to all the remaining docker files * fix tests * support torchcodec in audio classification and ASR * [commit to revert] build ci-dev images * [commit to revert] trigger circleci * [commit to revert] build ci-dev images * fix * fix modeling_hubert * backward compatible run_object_detection * revert ci trigger commits * fix mono conversion and support torch tensor as input * revert map_to_array docs + fix it * revert mono * nit in docstring * style * fix modular --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
) * fix dataset run_object_detection * bump version * keep same dataset actually * torchcodec in docstrings and testing utils * torchcodec in dockerfiles and requirements * remove duplicate * add torchocodec to all the remaining docker files * fix tests * support torchcodec in audio classification and ASR * [commit to revert] build ci-dev images * [commit to revert] trigger circleci * [commit to revert] build ci-dev images * fix * fix modeling_hubert * backward compatible run_object_detection * revert ci trigger commits * fix mono conversion and support torch tensor as input * revert map_to_array docs + fix it * revert mono * nit in docstring * style * fix modular --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
) * fix dataset run_object_detection * bump version * keep same dataset actually * torchcodec in docstrings and testing utils * torchcodec in dockerfiles and requirements * remove duplicate * add torchocodec to all the remaining docker files * fix tests * support torchcodec in audio classification and ASR * [commit to revert] build ci-dev images * [commit to revert] trigger circleci * [commit to revert] build ci-dev images * fix * fix modeling_hubert * backward compatible run_object_detection * revert ci trigger commits * fix mono conversion and support torch tensor as input * revert map_to_array docs + fix it * revert mono * nit in docstring * style * fix modular --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
) * fix dataset run_object_detection * bump version * keep same dataset actually * torchcodec in docstrings and testing utils * torchcodec in dockerfiles and requirements * remove duplicate * add torchocodec to all the remaining docker files * fix tests * support torchcodec in audio classification and ASR * [commit to revert] build ci-dev images * [commit to revert] trigger circleci * [commit to revert] build ci-dev images * fix * fix modeling_hubert * backward compatible run_object_detection * revert ci trigger commits * fix mono conversion and support torch tensor as input * revert map_to_array docs + fix it * revert mono * nit in docstring * style * fix modular --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
) * fix dataset run_object_detection * bump version * keep same dataset actually * torchcodec in docstrings and testing utils * torchcodec in dockerfiles and requirements * remove duplicate * add torchocodec to all the remaining docker files * fix tests * support torchcodec in audio classification and ASR * [commit to revert] build ci-dev images * [commit to revert] trigger circleci * [commit to revert] build ci-dev images * fix * fix modeling_hubert * backward compatible run_object_detection * revert ci trigger commits * fix mono conversion and support torch tensor as input * revert map_to_array docs + fix it * revert mono * nit in docstring * style * fix modular --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
) * fix dataset run_object_detection * bump version * keep same dataset actually * torchcodec in docstrings and testing utils * torchcodec in dockerfiles and requirements * remove duplicate * add torchocodec to all the remaining docker files * fix tests * support torchcodec in audio classification and ASR * [commit to revert] build ci-dev images * [commit to revert] trigger circleci * [commit to revert] build ci-dev images * fix * fix modeling_hubert * backward compatible run_object_detection * revert ci trigger commits * fix mono conversion and support torch tensor as input * revert map_to_array docs + fix it * revert mono * nit in docstring * style * fix modular --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
) * fix dataset run_object_detection * bump version * keep same dataset actually * torchcodec in docstrings and testing utils * torchcodec in dockerfiles and requirements * remove duplicate * add torchocodec to all the remaining docker files * fix tests * support torchcodec in audio classification and ASR * [commit to revert] build ci-dev images * [commit to revert] trigger circleci * [commit to revert] build ci-dev images * fix * fix modeling_hubert * backward compatible run_object_detection * revert ci trigger commits * fix mono conversion and support torch tensor as input * revert map_to_array docs + fix it * revert mono * nit in docstring * style * fix modular --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
continuation of #39060 (so this PR also contains the object detection fix so we can run the CI with
datasetsonmain)it also adds support for torchcodec.decoders.AudioDecoder as input to audio classification and asr pipelines