2x more memory efficient Graph-based RNN-T
State: closed | Pull request: yes
Labels: name: core

name: ASR

name: Run CICD

# What does this PR do ?

- reduces memory usage of Graph-Transducer by 2 times: Triton-based implementation of log-softmax operation for RNN-T 
  - idea: store log probabilities only for blank/target labels (needed to compute RNN-T loss), not for all logits
  - if we calculate full logits (Joint tensor), this is the optimal implementation: most of the memory is used by `logits/+gradients` (2x logits)
  - previous implementation required `logits/+gradients`, `log_probs/+gradients` (4x logits)
- adds an option to return RNN-T graphs from `forward` along with the loss value for further usage (e.g., using alignment)

**Example**: bfloat16, 15 sec, 8x subsampling (~FastConformer), 3 words/sec, vocab size 1024, batch size 32

|                         | Logits  | Extra Memory | Time     |
| ----------------------- | ------- | ------------ | -------- |
| Without Triton (before) | 1.04 GB | 3.20 GB      | 0.08 sec |
| **With Triton (here)**  | 1.04 GB | **1.13 GB**  | **0.06 sec** |

3x extra memory reduction, 2x total memory reduction (4.24 GB -> 2.17 GB).

Convergence: stable, see https://wandb.ai/nvidia/Graph_RNNT_Optimized

**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

```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**:
- [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?
- [x] Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
  - [x] Reviewer: Does the PR have correct import guards for all optional libraries?
  
**PR Type**:
- [x] 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)


[🤖]: Hi @artbataev 👋,

We wanted to let you know that a [CICD pipeline](https://github.com/NVIDIA/NeMo/actions/runs/12320247404) for this PR just finished successfully

So it might be time to merge this PR or get some approvals

I'm just a bot so I'll leave it you what to do next.

//cc @pablo-garay @ko3n1g

<!-- pylint-output-strict-mode-true -->

beep boop 🤖: 🚨 The following files must be fixed before merge!

---

Your code was analyzed with PyLint. The following annotations have been identified:

```

------------------------------------
Your code has been rated at 10.00/10
```

---

Thank you for improving NeMo's documentation!

<!-- pylint-output-strict-mode-true -->

beep boop 🤖: 🚨 The following files must be fixed before merge!

---

Your code was analyzed with PyLint. The following annotations have been identified:

```

------------------------------------
Your code has been rated at 10.00/10
```

---

Thank you for improving NeMo's documentation!

<!-- pylint-output-strict-mode-false -->

beep boop 🤖: 🙏 The following files have warnings. In case you are familiar with these, please try helping us to improve the code base.

---

Your code was analyzed with PyLint. The following annotations have been identified:

```

------------------------------------
Your code has been rated at 10.00/10
```

---

Thank you for improving NeMo's documentation!

[🤖]: Hi @artbataev 👋,

We wanted to let you know that a [CICD pipeline](https://github.com/NVIDIA/NeMo/actions/runs/12328248321) for this PR just finished successfully

So it might be time to merge this PR or get some approvals

I'm just a bot so I'll leave it you what to do next.

//cc @pablo-garay @ko3n1g