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

[do-not-merge] Illustration how to run audio+text dataloading #9131

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pzelasko
Copy link
Collaborator

@pzelasko pzelasko commented May 7, 2024

What does this PR do ?

The key config options to set are:

 +model.train_ds.input_cfg=/path/to/speech_text_input.yaml \
 +model.train_ds.use_multimodal_sampling=true \
 +model.train_ds.batch_tokens=65536 \
 +model.train_ds.token_equivalent_duration=0.08 \
 +model.train_ds.quadratic_factor=4096 \
 +model.train_ds.tarred_audio_filepaths=null \
 model.train_ds.manifest_filepath=null \
 model.train_ds.batch_size=null \
 model.train_ds.batch_duration=null \
 model.train_ds.use_lhotse=true \
 model.train_ds.use_bucketing=true \
 model.train_ds.num_buckets=30 \

The values of batch_tokens, token_equivalent_duration, and quadratic_factor need tuning.

where contents of speech_text_input.yaml are:

 - type: group
    weight: 1.0
    input_cfg:
    - type: nemo_tarred
      manifest_filepath: /path/to/manifest__OP_0..127_CL_.json
      tarred_audio_filepaths: /path/to/audio__OP_0..127_CL_.tar
      tags:
        pnc: 'no'
        source_lang: en
        target_lang: en
        taskname: asr
      weight: 1.0
    - type: nemo_sft_jsonl
      paths: /data/nemo_megatron_sft_chat_qa_data.shuf.jsonl
      language: en
      weight: 1.0

Collection: [Note which collection this PR will affect]

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)

Comment on lines +448 to +451
# elif cur_idx + tokenized_len < tgt_len:
# # Check whether the mask is applied to the correct position, the first token is turn start tokens
# if not torch.equal(target[cur_idx + 1 : cur_idx + tokenized_len], s_id[1:]):
# logging.warning("a sentence mismatches the corresponding piece " "in the conversation")

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
from lhotse.utils import Pathlike

from nemo.collections.common.data.lhotse.nemo_adapters import expand_sharded_filepaths
from nemo.collections.common.tokenizers.aggregate_tokenizer import AggregateTokenizer, TokenizerWrapper
from nemo.collections.common.tokenizers.tokenizer_spec import TokenizerSpec
from nemo.utils import logging

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'logging' is not used.
"label_start": "<extra_id_2>",
"end_of_turn": "\n",
"end_of_name": "\n",
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The special tokens are tricky: perhaps we need to ensure that they are included in the tokenizer's vocab.


return audio, audio_lens, tokens, token_lens, prompt_tokens, prompt_token_lens
return audio, audio_lens, tokens, token_lens, prompt_tokens, prompt_token_lens, text_minibatch
Copy link
Collaborator

Choose a reason for hiding this comment

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

copy the discussion note here and some followups in the end

supports 3 different strategies of mixing speech and text data
1.current strategy (sampled together as if it's one modality by projecting duration to equivalent token counts)
2.zip sampler strategy (separate sampler for each modality with separately defined batch_duration and batch_tokens, both samplers zipped to yield a mini-batch together)
3.round-robin strategy (separate samplers as in zip but the mini-batches are alternately yielded from each)

do we expect all the three strategies will return audio and text batch separately to the model like here?
if so, what do you think about also grouping the text-audio batch data in one dict like text-only batch (and in future, add audio-audio batch)

no need to do these in this PR but can be done on top of the canary-llm branch which has a speech SFT batch compatible with mtron

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's open for discussion. For the POC I separated text-only and audio-text portions of the mini-batch because it was easy to re-use the existing code and extend it with text-only branches. We could explore "fusing" those but we should design how the fused mini-batch would look like (e.g. do we introduce zero inputs in audio tensor for text-only examples? there will be a number of decisions to make here).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Initially, I wanted to return sth like:

@dataclass
class MultimodalQABatch:
    audio_text: dict  # dict might become a nested AudioTextQABatch dataclass, similar for other fields
    text_text: dict
    # ... could be extend with sub fields

But GPT SFT model code that we inherit from expects batch to be a dict and explicitly scans it for some fields like "tokens", also discards every key that has a non-tensor value. If we want to proceed with separate dataclasses or even dicts, we would need to override some fwd/bwd functions in the parent class.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's open for discussion. For the POC I separated text-only and audio-text portions of the mini-batch because it was easy to re-use the existing code and extend it with text-only branches. We could explore "fusing" those but we should design how the fused mini-batch would look like (e.g. do we introduce zero inputs in audio tensor for text-only examples? there will be a number of decisions to make here).

I actually like this design. we can leave how to "fuse" to the model code to decide, e.g. model code may want to concat speech and text batch together and do one fprop instead of two

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.

None yet

2 participants