MCPcopy Create free account
hub / github.com/FireRedTeam/FireRedTTS2 / lr_lambda

Method lr_lambda

fireredtts2/llm/utils.py:33–59  ·  view source on GitHub ↗
(self, step: int)

Source from the content-addressed store, hash-verified

31 super().__init__(optimizer, self.lr_lambda, last_epoch=-1)
32
33 def lr_lambda(self, step: int) -> float:
34 if step < self.warmup_steps:
35 return step / self.warmup_steps
36 else:
37 if self.decay_type == "linear":
38 return (self.total_steps - step) / (
39 self.total_steps - self.warmup_steps
40 )
41 elif self.decay_type == "constant":
42 return 1.0
43 elif self.decay_type == "exponential":
44 return 0.1 ** (
45 (step - self.warmup_steps) / (self.total_steps - self.warmup_steps)
46 )
47 elif self.decay_type == "cosine":
48 return 0.5 * (
49 1
50 + torch.cos(
51 torch.pi
52 * torch.tensor(
53 (step - self.warmup_steps)
54 / (self.total_steps - self.warmup_steps)
55 )
56 )
57 )
58 else:
59 raise ValueError(f"Invalid decay type: {self.decay_type}")
60
61
62additional_special_tokens = [

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected