Skip to content
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

[lhotse] Support for NeMo tarred manifests with offset field #10035

Merged
merged 7 commits into from
Aug 7, 2024

Conversation

pzelasko
Copy link
Collaborator

@pzelasko pzelasko commented Aug 3, 2024

What does this PR do ?

Support for NeMo tarred manifests with offset field in lhotse dataloading.

Collection: ASR

Changelog

  • Add specific line by line info of high level changes in this PR.

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this 

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

@pzelasko pzelasko requested a review from zhehuaichen August 3, 2024 02:28
@github-actions github-actions bot added the common label Aug 3, 2024
Signed-off-by: Piotr Żelasko <[email protected]>
Signed-off-by: Piotr Żelasko <[email protected]>
zhehuaichen added a commit to zhehuaichen/NeMo that referenced this pull request Aug 4, 2024
Signed-off-by: zhehuaichen <[email protected]>
@pzelasko pzelasko force-pushed the lhotse-nemo-tarred-with-offset branch from a72e988 to 60dae9f Compare August 5, 2024 15:01
@pzelasko pzelasko added Run CICD and removed Run CICD labels Aug 6, 2024
@@ -21,10 +21,11 @@
import numpy as np
import pytest
import torch
from lhotse import CutSet, MonoCut, NumpyFilesWriter, Recording
from lhotse import CutSet, MonoCut, NumpyFilesWriter, Recording, SupervisionSegment, compute_num_samples

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'SupervisionSegment' is not used.
Copy link
Collaborator

@zhehuaichen zhehuaichen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me . @KunalDhawan or @tango4j can either of you guys also take a look?
I will do a test with this PR

Copy link
Collaborator

@KunalDhawan KunalDhawan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you Piotr!

@pzelasko pzelasko added Run CICD and removed Run CICD labels Aug 6, 2024
@pzelasko pzelasko merged commit e5e648d into main Aug 7, 2024
225 checks passed
@pzelasko pzelasko deleted the lhotse-nemo-tarred-with-offset branch August 7, 2024 15:59
zhehuaichen added a commit to zhehuaichen/NeMo that referenced this pull request Aug 13, 2024
Signed-off-by: zhehuaichen <[email protected]>
@vadimkantorov
Copy link
Contributor

vadimkantorov commented Aug 30, 2024

@pzelasko I checked, caching TarInfos with a single linear scan lets then extract in O(1):

def taropen_build(tar_path):
    import tarfile
    tar = tarfile.open(tar_path)
    tarinfo_index = {tarinfo.name : tarinfo for tarinfo in tar.getmembers()}
    return lambda member_path, mode: tar.extractfile(tarinfo_index[member_path]) if mode == 'rb' else None

    # instead for uncompressed tars (which makes sense for audio files) can do without caching the TarInfo structure and just cache two ints per string file name, this makes it more amenable to sharing between DataLoader threads and easier to sync in tensors
    #import io
    #tarinfo_index = {tarinfo.name : (tarinfo.offset_data, tarinfo.size) for tarinfo in tar.getmembers()}
    #return lambda member_path, mode: [io.BytesIO(f.seek(e[0]) and f.read(e[1])) for f in [open(tar_path, mode)] for e in [tarinfo_index[member_path]]][0] if mode == 'rb' else None

if __name__ == '__main__':
    taropen = taropen_build('myfile.tar')
    print(taropen('mymember.txt', 'rb').read())

Supporting .tars with wav/opus files inside would be very nice, as these small audio files can be in 10s or 100s of thousands which is always a pressure on the file system and adds time to unpacking

@pzelasko
Copy link
Collaborator Author

We already support tars with wav/opus. Linear scan is not feasible for URL data sources (cloud storage, AIStore).

adityavavre pushed a commit to adityavavre/NeMo that referenced this pull request Sep 15, 2024
…10035)

* [lhotse] Support for NeMo tarred manifests with offset field

Signed-off-by: Piotr Żelasko <[email protected]>

* typo fix

Signed-off-by: Piotr Żelasko <[email protected]>

* fix basename

Signed-off-by: Piotr Żelasko <[email protected]>

* relieve heavy CPU memory usage for super-long tarred recordings

Signed-off-by: Piotr Żelasko <[email protected]>

* Tests and fixes

Signed-off-by: Piotr Żelasko <[email protected]>

---------

Signed-off-by: Piotr Żelasko <[email protected]>
Signed-off-by: adityavavre <[email protected]>
monica-sekoyan pushed a commit that referenced this pull request Oct 14, 2024
* [lhotse] Support for NeMo tarred manifests with offset field

Signed-off-by: Piotr Żelasko <[email protected]>

* typo fix

Signed-off-by: Piotr Żelasko <[email protected]>

* fix basename

Signed-off-by: Piotr Żelasko <[email protected]>

* relieve heavy CPU memory usage for super-long tarred recordings

Signed-off-by: Piotr Żelasko <[email protected]>

* Tests and fixes

Signed-off-by: Piotr Żelasko <[email protected]>

---------

Signed-off-by: Piotr Żelasko <[email protected]>
hainan-xv pushed a commit to hainan-xv/NeMo that referenced this pull request Nov 5, 2024
…10035)

* [lhotse] Support for NeMo tarred manifests with offset field

Signed-off-by: Piotr Żelasko <[email protected]>

* typo fix

Signed-off-by: Piotr Żelasko <[email protected]>

* fix basename

Signed-off-by: Piotr Żelasko <[email protected]>

* relieve heavy CPU memory usage for super-long tarred recordings

Signed-off-by: Piotr Żelasko <[email protected]>

* Tests and fixes

Signed-off-by: Piotr Żelasko <[email protected]>

---------

Signed-off-by: Piotr Żelasko <[email protected]>
Signed-off-by: Hainan Xu <[email protected]>
XuesongYang pushed a commit to paarthneekhara/NeMo that referenced this pull request Jan 18, 2025
…10035)

* [lhotse] Support for NeMo tarred manifests with offset field

Signed-off-by: Piotr Żelasko <[email protected]>

* typo fix

Signed-off-by: Piotr Żelasko <[email protected]>

* fix basename

Signed-off-by: Piotr Żelasko <[email protected]>

* relieve heavy CPU memory usage for super-long tarred recordings

Signed-off-by: Piotr Żelasko <[email protected]>

* Tests and fixes

Signed-off-by: Piotr Żelasko <[email protected]>

---------

Signed-off-by: Piotr Żelasko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants