Feature/conversations tarred
State: closed | Pull request: yes
Labels: name: common

# What does this PR do ?

Support for multimodal conversation tar format writing and reading.

Script usage:
```bash
python scripts/speech_llm/export_conversations_to_tar.py --shard-size 100 \
  in_manifest_conversations.jsonl \
  out_tarred_conversations
```

Example output:
```
$ out_tarred_conversations
audio_0.tar  audio_1.tar  audio_2.tar  manifest_0.jsonl  manifest_1.jsonl  manifest_2.jsonl
```

Example input_cfg for dataloader initialization:

```yaml
- input_cfg:
  - type: multimodal_conversation
     manifest_filepath: out_tarred_conversations/manifest_{0..2}.jsonl
     tarred_audio_filepaths: out_tarred_conversations/audio_{0..2}.tar
     audio_locator_tag: "[audio]"
```

Manifest JSONL format. One conversation per line. Mixed audio and text turns in user and assistant roles, supports {text,audio}-to-{text,audio}.
```
{"id":"page_0026_120644_conversation2","conversations":[{"value":"/data/conversations/mydataset/audio/user_turn0.wav","from":"User","type":"audio","duration":5.31},{"value":"Automatic speech recognition is a technology that allows computers to recognize and transcribe spoken language. In the NeMo Framework, ASR is used for tasks such as speech-to-text and voice recognition.","from":"Assistant","type":"text"},{"value":"/data/conversations/mydataset/audio/user_turn1.wav","from":"User","type":"audio","duration":5.61},{"value":"The NeMo Framework provides a range of tools and features for training and deploying ASR models, including model parallelism, data parallelism, and distributed checkpointing. This allows for faster training and inference times, as well as improved model accuracy and reliability.","from":"Assistant","type":"text"}]}
```

Unrolled for readability:

```
{
  "id": "page_0026_120644_conversation2",
  "conversations": [
    {
      "value": "/data/conversations/mydataset/audio/user_turn0.wav",
      "from": "User",
      "type": "audio",
      "duration": 5.31
    },
    {
      "value": "Automatic speech recognition is a technology that allows computers to recognize and transcribe spoken language. In the NeMo Framework, ASR is used for tasks such as speech-to-text and voice recognition.",
      "from": "Assistant",
      "type": "text"
    },
    {
      "value": "/data/conversations/mydataset/audio/user_turn1.wav",
      "from": "User",
      "type": "audio",
      "duration": 5.61
    },
    {
      "value": "The NeMo Framework provides a range of tools and features for training and deploying ASR models, including model parallelism, data parallelism, and distributed checkpointing. This allows for faster training and inference times, as well as improved model accuracy and reliability.",
      "from": "Assistant",
      "type": "text"
    }
  ]
}
```

The format stays the same after being exported to tarfile, but the audio turns are filled with the contents of the corresponding tar files on the fly.

JSONL manifest after tar export:

```
{
  "id": "page_0026_120644_conversation2",
  "conversations": [
    {
      "type": "audio",
      "from": "User",
      "duration": 5.3058125,
      "value": "user_turn0.flac"
    },
    {
      "type": "text",
      "from": "Assistant",
      "value": "Automatic speech recognition is a technology that allows computers to recognize and transcribe spoken language. In the NeMo Framework, ASR is used for tasks such as speech-to-text and voice recognition."
    },
    {
      "type": "audio",
      "from": "User",
      "duration": 5.607625,
      "value": "user_turn1.flac"
    },
    {
      "type": "text",
      "from": "Assistant",
      "value": "The NeMo Framework provides a range of tools and features for training and deploying ASR models, including model parallelism, data parallelism, and distributed checkpointing. This allows for faster training and inference times, as well as improved model accuracy and reliability."
    }
  ]
}
```

**Collection**: multimodal

# Changelog 
- Add specific line by line info of high level changes in this PR.

# Usage
* You can potentially add a usage example below

```python
# 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](https://github.com/NVIDIA/NeMo/blob/main/CONTRIBUTING.md)
- [ ] 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](https://github.com/NVIDIA/NeMo/blob/main/CONTRIBUTING.md) contains specific people who can review PRs to various areas.

# Additional Information
* Related to # (issue)


nice! 
1. can u add an example jsonl manifest in the PR description to show the idea after tarring?
2. can this PR get rid of pre-creating lhotse shar in speech-to-speech training example since now we have codec on the fly extraction on audio? 
+@subhankar-ghosh