| 64 | |
| 65 | |
| 66 | class LARS8bit(Optimizer1State): |
| 67 | def __init__( |
| 68 | self, |
| 69 | params, |
| 70 | lr, |
| 71 | momentum=0, |
| 72 | dampening=0, |
| 73 | weight_decay=0, |
| 74 | nesterov=False, |
| 75 | args=None, |
| 76 | min_8bit_size=4096, |
| 77 | max_unorm=0.02, |
| 78 | ): |
| 79 | """ |
| 80 | 8-bit LARS optimizer. |
| 81 | |
| 82 | Arguments: |
| 83 | params (`torch.tensor`): |
| 84 | The input parameters to optimize. |
| 85 | lr (`float`): |
| 86 | The learning rate. |
| 87 | momentum (`float`, defaults to 0): |
| 88 | The momentum value speeds up the optimizer by taking bigger steps. |
| 89 | dampening (`float`, defaults to 0): |
| 90 | The dampening value reduces the momentum of the optimizer. |
| 91 | weight_decay (`float`, defaults to 1e-2): |
| 92 | The weight decay value for the optimizer. |
| 93 | nesterov (`bool`, defaults to `False`): |
| 94 | Whether to use Nesterov momentum. |
| 95 | args (`object`, defaults to `None`): |
| 96 | An object with additional arguments. |
| 97 | min_8bit_size (`int`, defaults to 4096): |
| 98 | The minimum number of elements of the parameter tensors for 8-bit optimization. |
| 99 | max_unorm (`float`, defaults to 0.02): |
| 100 | The maximum gradient norm. |
| 101 | """ |
| 102 | if momentum == 0: |
| 103 | raise NotImplementedError("LARS without momentum is not supported!") |
| 104 | super().__init__( |
| 105 | "lars", |
| 106 | params, |
| 107 | lr, |
| 108 | (momentum, dampening), |
| 109 | 0.0, |
| 110 | weight_decay, |
| 111 | 8, |
| 112 | args, |
| 113 | min_8bit_size, |
| 114 | max_unorm=max_unorm, |
| 115 | ) |
| 116 | |
| 117 | |
| 118 | class LARS32bit(Optimizer1State): |
nothing calls this directly
no outgoing calls
no test coverage detected