#!/usr/bin/env python3 """REG-DROPOUT FIX 1 (2026-11-20): key-compatible FFN dropout. The first regdrop patch inserted nn.Dropout INTO the nn.Sequential FFNs of FusionBlock and DemoPerceiverBlock, shifting the second Linear from index 2 to index 3 and renaming its state-dict keys (ffn.2.* -> ffn.3.*). check_jedi caught it: init checkpoints no longer load. This fix restores the original Sequential layout (Linear, GELU, Linear) and applies dropout through a standalone `ffn_drop` attribute between the GELU and the second Linear, so every state-dict key is byte-identical to the pre-patch layout. (SwiGLUExpert was already key-safe: its `drop` is standalone.) Backups: .bak-regdropfix1-20261120. """ import py_compile import shutil import sys from pathlib import Path SRC = Path.home() / "lerobot/src/lerobot/policies/sera_vla_v3" BAK_SUFFIX = ".bak-regdropfix1-20261120" EDITS = { "modeling_base.py": [ ( """ self.ffn = nn.Sequential(nn.Linear(512, 2048), nn.GELU(), nn.Dropout(dropout), nn.Linear(2048, 512)) """, """ self.ffn = nn.Sequential(nn.Linear(512, 2048), nn.GELU(), nn.Linear(2048, 512)) self.ffn_drop = nn.Dropout(dropout) """, ), ( """ return q + self.ffn(self.norms[3](q)) """, """ h = self.norms[3](q) h = self.ffn[2](self.ffn_drop(self.ffn[1](self.ffn[0](h)))) return q + h """, ), ], "modeling_sera_vla_v3.py": [ ( """ self.ffn = nn.Sequential(nn.Linear(512, 2048), nn.GELU(), nn.Dropout(dropout), nn.Linear(2048, 512)) """, """ self.ffn = nn.Sequential(nn.Linear(512, 2048), nn.GELU(), nn.Linear(2048, 512)) self.ffn_drop = nn.Dropout(dropout) """, ), ( """ q = q + self.ffn(self.norm_f(q)) return q """, """ h = self.norm_f(q) h = self.ffn[2](self.ffn_drop(self.ffn[1](self.ffn[0](h)))) q = q + h return q """, ), ], } def main() -> int: for fname, edits in EDITS.items(): path = SRC / fname text = path.read_text() for i, (old, new) in enumerate(edits): if new in text and old not in text: print(f"{fname} edit {i}: already applied, skipping") continue count = text.count(old) assert count == 1, f"{fname} edit {i}: anchor found {count} times" text = text.replace(old, new) bak = path.with_name(path.name + BAK_SUFFIX) if not bak.exists(): shutil.copy2(path, bak) print(f"backup: {bak.name}") path.write_text(text) py_compile.compile(str(path), doraise=True) print(f"{fname}: {len(edits)} edits applied, compiles OK") print("REG-DROPOUT FIX1 DONE") return 0 if __name__ == "__main__": sys.exit(main())