A TTS that fits in your CPU (and pocket)
Python
Training: no weight decay on the text table (#396)
manu-lmcef8e2250662
diff --git a/training/tests/test_smoke.py b/training/tests/test_smoke.pyindex d6ba699..01b7b77 100644--- a/training/tests/test_smoke.py+++ b/training/tests/test_smoke.py@@ -153,6 +153,22 @@ def test_muon_splits_narrow_grouped_attention():assert [16, 8, 8] in sizes, sizes[email protected]("optim", ["adamw", "muon"])+def test_text_table_rows_without_gradient_keep_their_norm(optim: str):+ """A token absent from the data must not be decayed away (pocket-tts#390)."""+ model = tiny_model("lsd", **SMALL_OPTIONS)+ model.args.optim.type = optim+ optimizer = build_optimizer(model, model.args, torch.device("cpu"), rank=0)+ table = model.flow_lm.conditioner.embed.weight+ unseen = table[-2].detach().clone()+ for _ in range(3):+ optimizer.zero_grad()+ loss, _ = model(*make_batch())+ loss.backward()+ optimizer.step()+ assert torch.equal(table[-2], unseen)++@pytest.mark.parametrize("flow_type,cfg", [("lsd", 1.0), ("flow_matching", 1.0), ("drifting", 1.0)])def test_generate(flow_type: str, cfg: float):model = tiny_model(flow_type)diff --git a/training/train_utils.py b/training/train_utils.pyindex 66b8e7d..514fbc3 100644--- a/training/train_utils.py+++ b/training/train_utils.py@@ -237,9 +237,18 @@ def ensure_train_latents(def build_optimizer(model: TrainableTTS, args: TrainArgs, device: torch.device, rank: int) -> torch.optim.Optimizer:+ # No decay on the text table: rows of tokens the data never contains get no gradient, so+ # decay alone would shrink them to zero and the model could no longer say those words.+ table = model.flow_lm.conditioner.embed.weightif args.optim.type == "adamw":+ params = [p for p in model.parameters() if p.requires_grad and p is not table]+ no_decay = [table] if table.requires_grad else []return torch.optim.AdamW(- model.parameters(),+ [+ g+ for g in ({"params": params}, {"params": no_decay, "weight_decay": 0.0})+ if g["params"]+ ],lr=args.optim.lr,betas=args.optim.betas,eps=args.optim.eps,@@ -273,7 +282,11 @@ def build_optimizer(else:add(p)muon_params = {id(p) for ps in blocks.values() for p in ps}- rest = [p for p in model.parameters() if p.requires_grad and id(p) not in muon_params]+ rest = [+ p+ for p in model.parameters()+ if p.requires_grad and id(p) not in muon_params and p is not table+ ]muon_scale = 1.0 if args.optim.muon_rms_match else args.optim.muon_lr / args.optim.lr# Decoupled decay multiplies by (1 - lr * wd) per step; at muon_lr the same wd would# decay muon_scale times faster, so rescale it to the AdamW per-step decay.@@ -299,6 +312,15 @@ def build_optimizer("weight_decay": args.optim.weight_decay,})+ groups.append(+ {+ "params": [table] if table.requires_grad else [],+ "lr_scale": 1.0,+ "betas": args.optim.betas,+ "eps": args.optim.eps,+ "weight_decay": 0.0,+ }+ )groups = [g for g in groups if g["params"]]if rank == 0:n_split = sum(len(ps) for sizes, ps in blocks.items() if sizes)