Sortformer Diarizer 4spk v1 model PR Part 3: Speaker Diarization Mixin
State: closed | Pull request: yes
Labels: name: ASR

name: Speaker Tasks

name: common

name: Run CICD

# What does this PR do ?

Add diarization Mixin class to enable "one click" executable function (`diarize()`)  as in ASR collections' `transcribe()` functions.

1. wav filepath string
2. a list of wav filepath strings
3. json manifest filepath string

 Three types of input data is supported for 

Sortformer PRs:
This is PR 3rd out of 4.
PR 1/4: https://github.com/NVIDIA/NeMo/pull/11282
PR 2/4: https://github.com/NVIDIA/NeMo/pull/11336
PR 3/4: This PR
PR 4/4: Sortformer Documents 


**Collection**: [Note which collection this PR will affect]

# Changelog 

- `nemo/collections/asr/parts/mixins/diarization.py`
Mixin class for `diarize()` one click functions.

- `tests/collections/speaker_tasks/mixins/test_diarization.py`
Test file for mixin classes.


# Usage
* Three line example:
```python
from nemo.collections.asr.models import SortformerEncLabelModel
diar_model = SortformerEncLabelModel.restore_from(restore_path="diar_sortformer_4spk-v1", map_location=torch.device('cuda'), strict=False)
pred_outputs = diar_model.diarize(audio="my_audio.wav")
```

# GitHub Actions CI
Run CICD


# Before your PR is "Ready for review"
**Pre checks**:
- [x] Make sure you read and followed [Contributor guidelines](https://github.com/NVIDIA/NeMo/blob/main/CONTRIBUTING.md)
- [x] 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**:
- [x] New Feature
- [ ] Bugfix
- [ ] Documentation

## Who can review?

Anyone in NeMo ASR

# Additional Information

PR 1/4: https://github.com/NVIDIA/NeMo/pull/11282
PR 2/4: https://github.com/NVIDIA/NeMo/pull/11336


Don't forget to add `sync_dist=True` for validation
https://github.com/NVIDIA/NeMo/blob/38002a777075ceec16a67d31b011e1c2dcde50a2/nemo/collections/asr/models/asr_model.py#L204C9-L204C66

Note that we should make this change after @pzelasko 's PR https://github.com/NVIDIA/NeMo/pull/11533 is merged. Otherwise it will cause an error.


> Overall LGTM, just some small comments, and the only necessary change is to add `get_full_path()` to file paths when loading the manifest, such that relative paths can be properly handled. Another recommended change is to raise an error when `rttm_filepath` is a file that cannot be found, so that users can be notified of corrupted manifest

Makes lots of sense. Added file existence check then added `get_full_path()`
```python3
  if item['rttm_file'] is not None:
      if not os.path.exists(item['rttm_file']):
          raise FileNotFoundError(f"RTTM file not found: {item['rttm_file']}")
      else:
          item['rttm_file'] = get_full_path(audio_file=item['rttm_file'], manifest_file=manifest_file)
```

> Minor comments, the only necessary change is to move file existence checking after `get_full_path`.

Now all the existence check is moved after `get_full_path`. Thanks for commenting.