-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use soundfile for mp3 decoding instead of torchaudio #5573
Use soundfile for mp3 decoding instead of torchaudio #5573
Conversation
The documentation is not available anymore as the PR was closed or merged. |
…aries installation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff!
src/datasets/features/audio.py
Outdated
@@ -243,128 +236,52 @@ def path_to_bytes(path): | |||
storage = pa.StructArray.from_arrays([bytes_array, path_array], ["bytes", "path"], mask=bytes_array.is_null()) | |||
return array_cast(storage, self.pa_type) | |||
|
|||
def _decode_non_mp3_path_like( | |||
self, path, format=None, token_per_repo_id: Optional[Dict[str, Union[str, bool, None]]] = None | |||
def _decode_example( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can put all this logic in decode_example
and structure it the same way as in Image.decode_example
src/datasets/features/audio.py
Outdated
try: | ||
import librosa | ||
import soundfile as sf | ||
except ImportError as err: | ||
raise ImportError("To support decoding audio files, please install 'librosa' and 'soundfile'.") from err | ||
|
||
if format == "opus": | ||
if version.parse(sf.__libsndfile_version__) < version.parse("1.0.30"): | ||
if version.parse(sf.__libsndfile_version__) < version.parse("1.0.31"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can introduce 2 module-level variables for these checks:
IS_OPUS_SUPPORTED = version.parse(sf.__libsndfile_version__) < version.parse("1.0.31")
IS_MP3_SUPPORTED = version.parse(sf.__libsndfile_version__) < version.parse("1.0.31")
@mariosasko thank you for the review! do you have any idea why |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for also updating the docs!
Co-authored-by: Mario Šaško <[email protected]>
@polinaeterna The failure is due to @pklregister(obj_type)
def _save_tensor(pickler, obj):
# `torch.from_numpy` is not picklable in `torch>=1.11.0`
def _create_tensor(np_array):
return torch.from_numpy(np_array)
dill_log(pickler, f"To: {obj}")
args = (obj.detach().cpu().numpy(),)
pickler.save_reduce(_create_tensor, args, obj=obj)
dill_log(pickler, "# To")
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot ! you can merge when the CI is green (either with mario's fix or by skipping the torch test for recent torch versions if you think we need to fix it in another PR)
(doing a patch release now - please wait before merging ^^) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some additional comments
Co-authored-by: Mario Šaško <[email protected]>
@mariosasko génial, merci!! i've integrated all your changes, can you pls take a look one more time? |
Patch release is done (I did it from another branch than |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks all good now!
Show benchmarksPyArrow==6.0.0 Show updated benchmarks!Benchmark: benchmark_array_xd.json
Benchmark: benchmark_getitem_100B.json
Benchmark: benchmark_indices_mapping.json
Benchmark: benchmark_iterating.json
Benchmark: benchmark_map_filter.json
Show updated benchmarks!Benchmark: benchmark_array_xd.json
Benchmark: benchmark_getitem_100B.json
Benchmark: benchmark_indices_mapping.json
Benchmark: benchmark_iterating.json
Benchmark: benchmark_map_filter.json
|
I've removed
torchaudio
completely and switched to usesoundfile
for everything. With the new version ofsoundfile
package this should work smoothly because thelibsndfile
C library is bundled, in Linux wheels too.Let me know if you think it's too harsh and we should continue to support
torchaudio
decoding.I decided that we can drop it completely because:
torchaudio
(for example recently Error loading MP3 files from CommonVoice #5488 )torchaudio
versionsoundfile
is slightly faster then the latesttorchaudio
cc @sanchit-gandhi @vaibhavad