| 177 | |
| 178 | |
| 179 | class PagedAdam(Optimizer2State): |
| 180 | def __init__( |
| 181 | self, |
| 182 | params, |
| 183 | lr=1e-3, |
| 184 | betas=(0.9, 0.999), |
| 185 | eps=1e-8, |
| 186 | weight_decay=0, |
| 187 | amsgrad=False, |
| 188 | optim_bits=32, |
| 189 | args=None, |
| 190 | min_8bit_size=4096, |
| 191 | is_paged=False, |
| 192 | ): |
| 193 | """ |
| 194 | Paged Adam optimizer. |
| 195 | |
| 196 | Arguments: |
| 197 | params (`torch.tensor`): |
| 198 | The input parameters to optimize. |
| 199 | lr (`float`, defaults to 1e-3): |
| 200 | The learning rate. |
| 201 | betas (`tuple(float, float)`, defaults to (0.9, 0.999)): |
| 202 | The beta values are the decay rates of the first and second-order moment of the optimizer. |
| 203 | eps (`float`, defaults to 1e-8): |
| 204 | The epsilon value prevents division by zero in the optimizer. |
| 205 | weight_decay (`float`, defaults to 0.0): |
| 206 | The weight decay value for the optimizer. |
| 207 | amsgrad (`bool`, defaults to `False`): |
| 208 | Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead. |
| 209 | optim_bits (`int`, defaults to 32): |
| 210 | The number of bits of the optimizer state. |
| 211 | args (`object`, defaults to `None`): |
| 212 | An object with additional arguments. |
| 213 | min_8bit_size (`int`, defaults to 4096): |
| 214 | The minimum number of elements of the parameter tensors for 8-bit optimization. |
| 215 | is_paged (`bool`, defaults to `False`): |
| 216 | Whether the optimizer is a paged optimizer or not. |
| 217 | """ |
| 218 | super().__init__( |
| 219 | "adam", |
| 220 | params, |
| 221 | lr, |
| 222 | betas, |
| 223 | eps, |
| 224 | weight_decay, |
| 225 | optim_bits, |
| 226 | args, |
| 227 | min_8bit_size, |
| 228 | is_paged=True, |
| 229 | ) |
| 230 | |
| 231 | |
| 232 | class PagedAdam8bit(Optimizer2State): |
nothing calls this directly
no outgoing calls
no test coverage detected