[BUG] FlopsProfiler reports 0 MACs for nn.RNN / nn.GRU / nn.LSTM and their Cell variants

Aperta
#9,091 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@roshankumarg529 ci sta già lavorando.

Dal 15/11/2026.

  • #9090 di @roshankumarg529 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python, pytorch

Direzione di ricerca

Read _rnn_forward_hook and _rnn_cell_forward_hook in DeepSpeed's FlopsProfiler, along with MODULE_HOOK_MAPPING and the existing tests for RNN modules. Check how hooks update __flops__ and __macs__, then run the relevant profiler tests. Done means MAC totals and per-module MACs include the gate matrix multiplications for all six module types, including bidirectional and cell variants; a linked pull request is already open.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug training

Describe the bug

get_model_profile() and FlopsProfiler.get_total_macs() report 0 MACs for nn.RNN, nn.GRU, nn.LSTM, nn.RNNCell, nn.GRUCell and nn.LSTMCell, though FLOPs for the same modules are counted

These modules are handled by _rnn_forward_hook / _rnn_cell_forward_hook (via MODULE_HOOK_MAPPING) instead of the patched functionals, and register_module_hooks returns early for them. The hooks add to __flops__ but never to __macs__, so it stays at the 0 set in reset_profile

Nothing warns about this. In a model that mixes an LSTM with other layers, the MAC total silently includes only the non-RNN layers, and the per-module MACs in the printed profile are wrong the same way

#3816 / #3833 corrected the FLOPs of these hooks, but MACs were never counted for them

To Reproduce

import torch
from deepspeed.profiling.flops_profiler import get_model_profile

model = torch.nn.LSTM(8, 16, num_layers=2, batch_first=True)
flops, macs, params = get_model_profile(model, input_shape=(4, 5, 8),
                                        print_profile=False, as_string=False)
print(flops, macs)

Output on master (489c20a48): 149760 0

Expected behavior
AMACs should count the gate matmuls, the same way Linear is counted: one MAC per weight element of weight_ih and weight_hh per cell step, times batch × sequence length, times 2 if bidirectional.

For the model above:

  • layer 0: 4·16·(8+16) = 1536
  • layer 1: 4·16·(16+16) = 2048
  • total: (1536 + 2048) × 4 × 5 = 71680 MACs

System info

  • DeepSpeed: master @ 489c20a48
  • torch 2.15.0, CPU only, macOS arm64
  • Python: 3.12.0

Additional context
I have a fix with tests for all six module types (RNN/GRU/LSTM, including bidirectional, plus the three Cell variants) and will open a PR referencing this issue.

It touches _rnn_forward_hook near the lines changed by #8507 (PackedSequence crash), but it's an independent bug, and the two changes merge cleanly in either order. Once both land, the new MAC count also covers packed inputs, because it scales by the same batch_size * seq_length that #8507 corrects

Lingua principale
Python
Stelle
43.3k
Fork
5.1k
Merge medio
5g 10h
PR unite (30g)
85

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di deepspeedai/DeepSpeed

Tutte le issue di deepspeedai/DeepSpeed

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.