| 65 | |
| 66 | |
| 67 | class LAMB8bit(Optimizer2State): |
| 68 | def __init__( |
| 69 | self, |
| 70 | params, |
| 71 | lr=1e-3, |
| 72 | bias_correction=True, |
| 73 | betas=(0.9, 0.999), |
| 74 | eps=1e-8, |
| 75 | weight_decay=0, |
| 76 | amsgrad=False, |
| 77 | adam_w_mode=True, |
| 78 | args=None, |
| 79 | min_8bit_size=4096, |
| 80 | max_unorm=1.0, |
| 81 | ): |
| 82 | """ |
| 83 | 8-bit LAMB optimizer. |
| 84 | |
| 85 | Arguments: |
| 86 | params (`torch.tensor`): |
| 87 | The input parameters to optimize. |
| 88 | lr (`float`, defaults to 1e-3): |
| 89 | The learning rate. |
| 90 | bias_correction (`bool`, defaults to `True`): |
| 91 | Whether to apply bias correction to the first and second-order moments. |
| 92 | betas (`tuple(float, float)`, defaults to (0.9, 0.999)): |
| 93 | The beta values are the decay rates of the first and second-order moment of the optimizer. |
| 94 | eps (`float`, defaults to 1e-8): |
| 95 | The epsilon value prevents division by zero in the optimizer. |
| 96 | weight_decay (`float`, defaults to 1e-2): |
| 97 | The weight decay value for the optimizer. |
| 98 | amsgrad (`bool`, defaults to `False`): |
| 99 | Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead. |
| 100 | Note: This parameter is not supported in LAMB8bit and must be False. |
| 101 | adam_w_mode (`bool`, defaults to `True`): |
| 102 | Whether to use the AdamW variant. |
| 103 | args (`object`, defaults to `None`): |
| 104 | An object with additional arguments. |
| 105 | min_8bit_size (`int`, defaults to 4096): |
| 106 | The minimum number of elements of the parameter tensors for 8-bit optimization. |
| 107 | max_unorm (`float`, defaults to 1.0): |
| 108 | The maximum update norm for trust-ratio clipping. |
| 109 | Note: This parameter is not supported in LAMB8bit and must be left at the |
| 110 | default 1.0. The 8-bit blockwise update does not implement update-norm |
| 111 | clipping; it is honored by the 32-bit LAMB / LAMB32bit optimizers. |
| 112 | """ |
| 113 | # Validate unsupported parameters |
| 114 | if amsgrad: |
| 115 | raise ValueError("LAMB8bit does not support amsgrad=True") |
| 116 | |
| 117 | if max_unorm != 1.0: |
| 118 | # We allow the default value of 1.0 to maintain compatibility with the function |
| 119 | # signature, but the 8-bit blockwise update does not implement update-norm |
| 120 | # clipping, so any other value would be silently ignored. |
| 121 | raise ValueError("LAMB8bit only supports max_unorm=1.0 (default value for compatibility)") |
| 122 | |
| 123 | super().__init__( |
| 124 | "lamb", |
nothing calls this directly
no outgoing calls
no test coverage detected