Proposal: Add a StochasticDepth (DropPath) module to flax.nnx
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- machine-learning
Direzione di ricerca
Start with flax/nnx/nn/stochastic.py and the existing Dropout implementation, then check its tests, exports, and API documentation to follow NNX conventions. The proposal lists the required behavior and tests, including eval and zero-rate identity, rate-one behavior, per-sample broadcasting, rescaling, JIT, and RNG handling. Done means the module is exported as nnx.StochasticDepth, documented with an example, and covered by those tests.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Motivation
Stochastic depth (Huang et al., "Deep Networks with Stochastic Depth", ECCV 2016) trains residual networks by randomly dropping entire residual branches per sample during training and using the full network at test time. It is a standard regularizer for modern residual architectures (ViT, ConvNeXt, Swin-style models): torchvision ships it as a first-class module and timm exposes it as DropPath, and training recipes for these architectures assume it is available.
Flax NNX currently has nnx.Dropout but no stochastic depth. The two are not interchangeable: dropout masks individual activations, while stochastic depth drops the whole residual branch for a sample (and rescales the surviving branches), which is what lets very deep residual networks train as an ensemble of shallower ones. When I went to port a ViT-style training recipe to NNX I had to hand-roll this, and the per-sample broadcasting and train-time rescaling are easy to get subtly wrong.
I checked before filing: there is no StochasticDepth / DropPath implementation in Flax (code search returns zero), no open issue requesting it, and no open or closed PR implementing it.
Proposed design
Add StochasticDepth to flax/nnx/nn/stochastic.py, next to Dropout, mirroring its API and conventions so it feels native to NNX:
class StochasticDepth(nnx.Module):
def __init__(
self,
rate: float, # drop probability (not keep rate), like Dropout
*,
deterministic: bool | None = False,
rng_collection: str = "dropout",
rngs: nnx.Rngs | None = None,
): ...
def __call__(self, inputs, *, deterministic=None, rngs=None):
# training: draw one Bernoulli(1 - rate) per sample (leading axis),
# broadcast it over all remaining axes, zero dropped samples and
# scale survivors by 1 / (1 - rate)
# eval / rate == 0: return inputs unchanged
Usage inside a residual block:
class Block(nnx.Module):
def __init__(self, dim, drop_path_rate, rngs):
self.mlp = ...
self.drop_path = nnx.StochasticDepth(drop_path_rate, rngs=rngs)
def __call__(self, x):
return x + self.drop_path(self.mlp(x))
It would be exported as nnx.StochasticDepth, registered in the NNX API docs next to Dropout, and support model.train() / model.eval() and nnx.view(..., deterministic=...) the same way Dropout does (via set_view).
Scope
In scope: the NNX module, unit tests (identity at eval and at rate 0, all-dropped/zero behaviour at rate 1, per-sample mask broadcasting, train-time rescaling, jit compatibility, rng handling), docs/API registration, and a short usage example in the module docstring.
Out of scope for a first PR: a linen version (happy to do it as a follow-up if maintainers want both), and per-layer rate scheduling helpers (e.g. linearly increasing rates across blocks) — users can construct per-block rates themselves.
Offer
I am willing to implement this and maintain it through review. I would welcome a maintainer or mentor to guide it — in particular on whether the NNX-only scope is right and on the rng_collection naming — before I open the PR, so the design lands in the shape you want.
- Lingua principale
- Jupyter Notebook
- Stelle
- 7.4k
- Fork
- 855
- Merge medio
- 3g 3h
- PR unite (30g)
- 5
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/flax
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 3 giorni
-
nnx.Embed resolves dtype=None at construction, so it diverges from linen.EmbedForse già presa @mahdi-shafiei l’ha presa 10 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 3 giorni
-
MultiHeadAttention documentation missing descriptions of `None` values for optional argumentsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 3 giorni
-
RNN returns a wrong final carry (or raises) with seq_lengths and more than one batch dimensionForse già presa @bhaskargurram-ai l’ha presa 15 giorni fa. Aperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 72/100
I maintainer di solito rispondono entro 3 giorni
-
nnx.EMA.update fails when the model holds RNG state (e.g. nnx.Dropout with rngs)Forse già presa @Arthur031221 l’ha presa 62 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 3 giorni
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 87/100
deepset-ai/haystack-integrations#815 ·
I maintainer di solito rispondono entro 12 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
tensorflow/datasets#11260 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
Niko1221/Strata#7537 · 3 commenti ·
I maintainer di solito rispondono entro 4 giorni
-
load_model_from_checkpoint drops num_out/signal_in_channels for models whose __init__ takes **kwargsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno