bitsandbytes 0.50.0__py3-none-win_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. bitsandbytes/__init__.py +78 -0
  2. bitsandbytes/__main__.py +4 -0
  3. bitsandbytes/_ops.py +510 -0
  4. bitsandbytes/autograd/__init__.py +0 -0
  5. bitsandbytes/autograd/_functions.py +491 -0
  6. bitsandbytes/backends/__init__.py +0 -0
  7. bitsandbytes/backends/cpu/__init__.py +0 -0
  8. bitsandbytes/backends/cpu/ops.py +580 -0
  9. bitsandbytes/backends/cuda/__init__.py +0 -0
  10. bitsandbytes/backends/cuda/ops.py +1199 -0
  11. bitsandbytes/backends/default/__init__.py +0 -0
  12. bitsandbytes/backends/default/ops.py +632 -0
  13. bitsandbytes/backends/hpu/__init__.py +0 -0
  14. bitsandbytes/backends/hpu/ops.py +53 -0
  15. bitsandbytes/backends/mps/__init__.py +0 -0
  16. bitsandbytes/backends/mps/ops.py +277 -0
  17. bitsandbytes/backends/triton/__init__.py +0 -0
  18. bitsandbytes/backends/triton/kernels_4bit.py +577 -0
  19. bitsandbytes/backends/triton/kernels_8bit_quant.py +195 -0
  20. bitsandbytes/backends/triton/kernels_optim.py +1177 -0
  21. bitsandbytes/backends/triton/ops.py +304 -0
  22. bitsandbytes/backends/utils.py +94 -0
  23. bitsandbytes/backends/xpu/__init__.py +0 -0
  24. bitsandbytes/backends/xpu/ops.py +305 -0
  25. bitsandbytes/cextension.py +405 -0
  26. bitsandbytes/consts.py +12 -0
  27. bitsandbytes/cuda_specs.py +111 -0
  28. bitsandbytes/diagnostics/__init__.py +0 -0
  29. bitsandbytes/diagnostics/cuda.py +193 -0
  30. bitsandbytes/diagnostics/main.py +134 -0
  31. bitsandbytes/diagnostics/utils.py +12 -0
  32. bitsandbytes/functional.py +1810 -0
  33. bitsandbytes/libbitsandbytes_cpu.dll +0 -0
  34. bitsandbytes/nn/__init__.py +19 -0
  35. bitsandbytes/nn/modules.py +1220 -0
  36. bitsandbytes/nn/parametrize.py +206 -0
  37. bitsandbytes/optim/__init__.py +22 -0
  38. bitsandbytes/optim/adagrad.py +187 -0
  39. bitsandbytes/optim/adam.py +346 -0
  40. bitsandbytes/optim/adamw.py +337 -0
  41. bitsandbytes/optim/ademamix.py +410 -0
  42. bitsandbytes/optim/lamb.py +190 -0
  43. bitsandbytes/optim/lars.py +259 -0
  44. bitsandbytes/optim/lion.py +266 -0
  45. bitsandbytes/optim/optimizer.py +756 -0
  46. bitsandbytes/optim/rmsprop.py +170 -0
  47. bitsandbytes/optim/sgd.py +152 -0
  48. bitsandbytes/py.typed +0 -0
  49. bitsandbytes/utils.py +208 -0
  50. bitsandbytes-0.50.0.dist-info/METADATA +288 -0
  51. bitsandbytes-0.50.0.dist-info/RECORD +54 -0
  52. bitsandbytes-0.50.0.dist-info/WHEEL +5 -0
  53. bitsandbytes-0.50.0.dist-info/licenses/LICENSE +21 -0
  54. bitsandbytes-0.50.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,346 @@
1
+ # Copyright (c) Facebook, Inc. and its affiliates.
2
+ #
3
+ # This source code is licensed under the MIT license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ from bitsandbytes.optim.optimizer import Optimizer2State
7
+
8
+
9
+ class Adam(Optimizer2State):
10
+ def __init__(
11
+ self,
12
+ params,
13
+ lr=1e-3,
14
+ betas=(0.9, 0.999),
15
+ eps=1e-8,
16
+ weight_decay=0,
17
+ amsgrad=False,
18
+ optim_bits=32,
19
+ args=None,
20
+ min_8bit_size=4096,
21
+ is_paged=False,
22
+ ):
23
+ """
24
+ Base Adam optimizer.
25
+
26
+ Arguments:
27
+ params (`torch.tensor`):
28
+ The input parameters to optimize.
29
+ lr (`float`, defaults to 1e-3):
30
+ The learning rate.
31
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
32
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
33
+ eps (`float`, defaults to 1e-8):
34
+ The epsilon value prevents division by zero in the optimizer.
35
+ weight_decay (`float`, defaults to 0.0):
36
+ The weight decay value for the optimizer.
37
+ amsgrad (`bool`, defaults to `False`):
38
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
39
+ optim_bits (`int`, defaults to 32):
40
+ The number of bits of the optimizer state.
41
+ args (`object`, defaults to `None`):
42
+ An object with additional arguments.
43
+ min_8bit_size (`int`, defaults to 4096):
44
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
45
+ is_paged (`bool`, defaults to `False`):
46
+ Whether the optimizer is a paged optimizer or not.
47
+ """
48
+ super().__init__(
49
+ "adam",
50
+ params,
51
+ lr,
52
+ betas,
53
+ eps,
54
+ weight_decay,
55
+ optim_bits,
56
+ args,
57
+ min_8bit_size,
58
+ is_paged=is_paged,
59
+ )
60
+
61
+
62
+ class Adam8bit(Optimizer2State):
63
+ def __init__(
64
+ self,
65
+ params,
66
+ lr=1e-3,
67
+ betas=(0.9, 0.999),
68
+ eps=1e-8,
69
+ weight_decay=0,
70
+ amsgrad=False,
71
+ optim_bits=32,
72
+ args=None,
73
+ min_8bit_size=4096,
74
+ is_paged=False,
75
+ ):
76
+ """
77
+ 8-bit Adam optimizer.
78
+
79
+ Arguments:
80
+ params (`torch.tensor`):
81
+ The input parameters to optimize.
82
+ lr (`float`, defaults to 1e-3):
83
+ The learning rate.
84
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
85
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
86
+ eps (`float`, defaults to 1e-8):
87
+ The epsilon value prevents division by zero in the optimizer.
88
+ weight_decay (`float`, defaults to 0.0):
89
+ The weight decay value for the optimizer.
90
+ amsgrad (`bool`, defaults to `False`):
91
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
92
+ Note: This parameter is not supported in Adam8bit and must be False.
93
+ optim_bits (`int`, defaults to 32):
94
+ The number of bits of the optimizer state.
95
+ Note: This parameter is not used in Adam8bit as it always uses 8-bit optimization.
96
+ args (`object`, defaults to `None`):
97
+ An object with additional arguments.
98
+ min_8bit_size (`int`, defaults to 4096):
99
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
100
+ is_paged (`bool`, defaults to `False`):
101
+ Whether the optimizer is a paged optimizer or not.
102
+ """
103
+ # Validate unsupported parameters
104
+ if amsgrad:
105
+ raise ValueError("Adam8bit does not support amsgrad=True")
106
+
107
+ if optim_bits != 32:
108
+ # We allow the default value of 32 to maintain compatibility with the function signature,
109
+ # but any other value is invalid since Adam8bit always uses 8-bit optimization
110
+ raise ValueError("Adam8bit only supports optim_bits=32 (default value for compatibility)")
111
+
112
+ super().__init__(
113
+ "adam",
114
+ params,
115
+ lr,
116
+ betas,
117
+ eps,
118
+ weight_decay,
119
+ 8, # Hardcoded to 8 bits
120
+ args,
121
+ min_8bit_size,
122
+ is_paged=is_paged,
123
+ )
124
+
125
+
126
+ class Adam32bit(Optimizer2State):
127
+ def __init__(
128
+ self,
129
+ params,
130
+ lr=1e-3,
131
+ betas=(0.9, 0.999),
132
+ eps=1e-8,
133
+ weight_decay=0,
134
+ amsgrad=False,
135
+ optim_bits=32,
136
+ args=None,
137
+ min_8bit_size=4096,
138
+ is_paged=False,
139
+ ):
140
+ """
141
+ 32-bit Adam optimizer.
142
+
143
+ Arguments:
144
+ params (`torch.tensor`):
145
+ The input parameters to optimize.
146
+ lr (`float`, defaults to 1e-3):
147
+ The learning rate.
148
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
149
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
150
+ eps (`float`, defaults to 1e-8):
151
+ The epsilon value prevents division by zero in the optimizer.
152
+ weight_decay (`float`, defaults to 0.0):
153
+ The weight decay value for the optimizer.
154
+ amsgrad (`bool`, defaults to `False`):
155
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
156
+ optim_bits (`int`, defaults to 32):
157
+ The number of bits of the optimizer state.
158
+ args (`object`, defaults to `None`):
159
+ An object with additional arguments.
160
+ min_8bit_size (`int`, defaults to 4096):
161
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
162
+ is_paged (`bool`, defaults to `False`):
163
+ Whether the optimizer is a paged optimizer or not.
164
+ """
165
+ super().__init__(
166
+ "adam",
167
+ params,
168
+ lr,
169
+ betas,
170
+ eps,
171
+ weight_decay,
172
+ 32,
173
+ args,
174
+ min_8bit_size,
175
+ is_paged=is_paged,
176
+ )
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):
233
+ def __init__(
234
+ self,
235
+ params,
236
+ lr=1e-3,
237
+ betas=(0.9, 0.999),
238
+ eps=1e-8,
239
+ weight_decay=0,
240
+ amsgrad=False,
241
+ optim_bits=32,
242
+ args=None,
243
+ min_8bit_size=4096,
244
+ is_paged=False,
245
+ ):
246
+ """
247
+ 8-bit paged Adam optimizer.
248
+
249
+ Arguments:
250
+ params (`torch.tensor`):
251
+ The input parameters to optimize.
252
+ lr (`float`, defaults to 1e-3):
253
+ The learning rate.
254
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
255
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
256
+ eps (`float`, defaults to 1e-8):
257
+ The epsilon value prevents division by zero in the optimizer.
258
+ weight_decay (`float`, defaults to 0.0):
259
+ The weight decay value for the optimizer.
260
+ amsgrad (`bool`, defaults to `False`):
261
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
262
+ Note: This parameter is not supported in PagedAdam8bit and must be False.
263
+ optim_bits (`int`, defaults to 32):
264
+ The number of bits of the optimizer state.
265
+ Note: This parameter is not used in PagedAdam8bit as it always uses 8-bit optimization.
266
+ args (`object`, defaults to `None`):
267
+ An object with additional arguments.
268
+ min_8bit_size (`int`, defaults to 4096):
269
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
270
+ is_paged (`bool`, defaults to `False`):
271
+ Whether the optimizer is a paged optimizer or not.
272
+ """
273
+ # Validate unsupported parameters
274
+ if amsgrad:
275
+ raise ValueError("PagedAdam8bit does not support amsgrad=True")
276
+
277
+ if optim_bits != 32:
278
+ # We allow the default value of 32 to maintain compatibility with the function signature,
279
+ # but any other value is invalid since PagedAdam8bit always uses 8-bit optimization
280
+ raise ValueError("PagedAdam8bit only supports optim_bits=32 (default value for compatibility)")
281
+
282
+ super().__init__(
283
+ "adam",
284
+ params,
285
+ lr,
286
+ betas,
287
+ eps,
288
+ weight_decay,
289
+ 8, # Hardcoded to 8 bits
290
+ args,
291
+ min_8bit_size,
292
+ is_paged=True,
293
+ )
294
+
295
+
296
+ class PagedAdam32bit(Optimizer2State):
297
+ def __init__(
298
+ self,
299
+ params,
300
+ lr=1e-3,
301
+ betas=(0.9, 0.999),
302
+ eps=1e-8,
303
+ weight_decay=0,
304
+ amsgrad=False,
305
+ optim_bits=32,
306
+ args=None,
307
+ min_8bit_size=4096,
308
+ is_paged=False,
309
+ ):
310
+ """
311
+ Paged 32-bit Adam optimizer.
312
+
313
+ Arguments:
314
+ params (`torch.tensor`):
315
+ The input parameters to optimize.
316
+ lr (`float`, defaults to 1e-3):
317
+ The learning rate.
318
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
319
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
320
+ eps (`float`, defaults to 1e-8):
321
+ The epsilon value prevents division by zero in the optimizer.
322
+ weight_decay (`float`, defaults to 0.0):
323
+ The weight decay value for the optimizer.
324
+ amsgrad (`bool`, defaults to `False`):
325
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
326
+ optim_bits (`int`, defaults to 32):
327
+ The number of bits of the optimizer state.
328
+ args (`object`, defaults to `None`):
329
+ An object with additional arguments.
330
+ min_8bit_size (`int`, defaults to 4096):
331
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
332
+ is_paged (`bool`, defaults to `False`):
333
+ Whether the optimizer is a paged optimizer or not.
334
+ """
335
+ super().__init__(
336
+ "adam",
337
+ params,
338
+ lr,
339
+ betas,
340
+ eps,
341
+ weight_decay,
342
+ 32,
343
+ args,
344
+ min_8bit_size,
345
+ is_paged=True,
346
+ )
@@ -0,0 +1,337 @@
1
+ # Copyright (c) Facebook, Inc. and its affiliates.
2
+ #
3
+ # This source code is licensed under the MIT license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ from bitsandbytes.optim.optimizer import Optimizer2State
7
+
8
+
9
+ class AdamW(Optimizer2State):
10
+ def __init__(
11
+ self,
12
+ params,
13
+ lr=1e-3,
14
+ betas=(0.9, 0.999),
15
+ eps=1e-8,
16
+ weight_decay=1e-2,
17
+ amsgrad=False,
18
+ optim_bits=32,
19
+ args=None,
20
+ min_8bit_size=4096,
21
+ is_paged=False,
22
+ ):
23
+ """
24
+ Base AdamW optimizer.
25
+
26
+ Arguments:
27
+ params (`torch.Tensor`):
28
+ The input parameters to optimize.
29
+ lr (`float`, defaults to 1e-3):
30
+ The learning rate.
31
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
32
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
33
+ eps (`float`, defaults to 1e-8):
34
+ The epsilon value prevents division by zero in the optimizer.
35
+ weight_decay (`float`, defaults to 1e-2):
36
+ The weight decay value for the optimizer.
37
+ amsgrad (`bool`, defaults to `False`):
38
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
39
+ optim_bits (`int`, defaults to 32):
40
+ The number of bits of the optimizer state.
41
+ args (`object`, defaults to `None`):
42
+ An object with additional arguments.
43
+ min_8bit_size (`int`, defaults to 4096):
44
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
45
+ is_paged (`bool`, defaults to `False`):
46
+ Whether the optimizer is a paged optimizer or not.
47
+ """
48
+ super().__init__(
49
+ "adam",
50
+ params,
51
+ lr,
52
+ betas,
53
+ eps,
54
+ weight_decay,
55
+ optim_bits,
56
+ args,
57
+ min_8bit_size,
58
+ is_paged=is_paged,
59
+ )
60
+
61
+
62
+ class AdamW8bit(Optimizer2State):
63
+ def __init__(
64
+ self,
65
+ params,
66
+ lr=1e-3,
67
+ betas=(0.9, 0.999),
68
+ eps=1e-8,
69
+ weight_decay=1e-2,
70
+ amsgrad=False,
71
+ optim_bits=32,
72
+ args=None,
73
+ min_8bit_size=4096,
74
+ is_paged=False,
75
+ ):
76
+ """
77
+ 8-bit AdamW optimizer.
78
+
79
+ Arguments:
80
+ params (`torch.Tensor`):
81
+ The input parameters to optimize.
82
+ lr (`float`, defaults to 1e-3):
83
+ The learning rate.
84
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
85
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
86
+ eps (`float`, defaults to 1e-8):
87
+ The epsilon value prevents division by zero in the optimizer.
88
+ weight_decay (`float`, defaults to 1e-2):
89
+ The weight decay value for the optimizer.
90
+ amsgrad (`bool`, defaults to `False`):
91
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
92
+ Note: This parameter is not supported in AdamW8bit and must be False.
93
+ optim_bits (`int`, defaults to 32):
94
+ The number of bits of the optimizer state.
95
+ Note: This parameter is not used in AdamW8bit as it always uses 8-bit optimization.
96
+ args (`object`, defaults to `None`):
97
+ An object with additional arguments.
98
+ min_8bit_size (`int`, defaults to 4096):
99
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
100
+ is_paged (`bool`, defaults to `False`):
101
+ Whether the optimizer is a paged optimizer or not.
102
+ """
103
+ # Validate unsupported parameters
104
+ if amsgrad:
105
+ raise ValueError("AdamW8bit does not support amsgrad=True")
106
+
107
+ if optim_bits != 32:
108
+ # We allow the default value of 32 to maintain compatibility with the function signature,
109
+ # but any other value is invalid since AdamW8bit always uses 8-bit optimization
110
+ raise ValueError("AdamW8bit only supports optim_bits=32 (default value for compatibility)")
111
+
112
+ super().__init__(
113
+ "adam",
114
+ params,
115
+ lr,
116
+ betas,
117
+ eps,
118
+ weight_decay,
119
+ 8, # Hardcoded to 8 bits
120
+ args,
121
+ min_8bit_size,
122
+ is_paged=is_paged,
123
+ )
124
+
125
+
126
+ class AdamW32bit(Optimizer2State):
127
+ def __init__(
128
+ self,
129
+ params,
130
+ lr=1e-3,
131
+ betas=(0.9, 0.999),
132
+ eps=1e-8,
133
+ weight_decay=1e-2,
134
+ amsgrad=False,
135
+ optim_bits=32,
136
+ args=None,
137
+ min_8bit_size=4096,
138
+ is_paged=False,
139
+ ):
140
+ """
141
+ 32-bit AdamW optimizer.
142
+
143
+ Arguments:
144
+ params (`torch.Tensor`):
145
+ The input parameters to optimize.
146
+ lr (`float`, defaults to 1e-3):
147
+ The learning rate.
148
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
149
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
150
+ eps (`float`, defaults to 1e-8):
151
+ The epsilon value prevents division by zero in the optimizer.
152
+ weight_decay (`float`, defaults to 1e-2):
153
+ The weight decay value for the optimizer.
154
+ amsgrad (`bool`, defaults to `False`):
155
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
156
+ optim_bits (`int`, defaults to 32):
157
+ The number of bits of the optimizer state.
158
+ args (`object`, defaults to `None`):
159
+ An object with additional arguments.
160
+ min_8bit_size (`int`, defaults to 4096):
161
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
162
+ is_paged (`bool`, defaults to `False`):
163
+ Whether the optimizer is a paged optimizer or not.
164
+ """
165
+ super().__init__(
166
+ "adam",
167
+ params,
168
+ lr,
169
+ betas,
170
+ eps,
171
+ weight_decay,
172
+ 32,
173
+ args,
174
+ min_8bit_size,
175
+ is_paged=is_paged,
176
+ )
177
+
178
+
179
+ class PagedAdamW(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=1e-2,
187
+ amsgrad=False,
188
+ optim_bits=32,
189
+ args=None,
190
+ min_8bit_size=4096,
191
+ ):
192
+ """
193
+ Paged AdamW optimizer.
194
+
195
+ Arguments:
196
+ params (`torch.Tensor`):
197
+ The input parameters to optimize.
198
+ lr (`float`, defaults to 1e-3):
199
+ The learning rate.
200
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
201
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
202
+ eps (`float`, defaults to 1e-8):
203
+ The epsilon value prevents division by zero in the optimizer.
204
+ weight_decay (`float`, defaults to 1e-2):
205
+ The weight decay value for the optimizer.
206
+ amsgrad (`bool`, defaults to `False`):
207
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
208
+ optim_bits (`int`, defaults to 32):
209
+ The number of bits of the optimizer state.
210
+ args (`object`, defaults to `None`):
211
+ An object with additional arguments.
212
+ min_8bit_size (`int`, defaults to 4096):
213
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
214
+ """
215
+ super().__init__(
216
+ "adam",
217
+ params,
218
+ lr,
219
+ betas,
220
+ eps,
221
+ weight_decay,
222
+ optim_bits,
223
+ args,
224
+ min_8bit_size,
225
+ is_paged=True,
226
+ )
227
+
228
+
229
+ class PagedAdamW8bit(Optimizer2State):
230
+ def __init__(
231
+ self,
232
+ params,
233
+ lr=1e-3,
234
+ betas=(0.9, 0.999),
235
+ eps=1e-8,
236
+ weight_decay=1e-2,
237
+ amsgrad=False,
238
+ optim_bits=32,
239
+ args=None,
240
+ min_8bit_size=4096,
241
+ ):
242
+ """
243
+ Paged 8-bit AdamW optimizer.
244
+
245
+ Arguments:
246
+ params (`torch.Tensor`):
247
+ The input parameters to optimize.
248
+ lr (`float`, defaults to 1e-3):
249
+ The learning rate.
250
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
251
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
252
+ eps (`float`, defaults to 1e-8):
253
+ The epsilon value prevents division by zero in the optimizer.
254
+ weight_decay (`float`, defaults to 1e-2):
255
+ The weight decay value for the optimizer.
256
+ amsgrad (`bool`, defaults to `False`):
257
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
258
+ Note: This parameter is not supported in PagedAdamW8bit and must be False.
259
+ optim_bits (`int`, defaults to 32):
260
+ The number of bits of the optimizer state.
261
+ Note: This parameter is not used in PagedAdamW8bit as it always uses 8-bit optimization.
262
+ args (`object`, defaults to `None`):
263
+ An object with additional arguments.
264
+ min_8bit_size (`int`, defaults to 4096):
265
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
266
+ """
267
+ # Validate unsupported parameters
268
+ if amsgrad:
269
+ raise ValueError("PagedAdamW8bit does not support amsgrad=True")
270
+
271
+ if optim_bits != 32:
272
+ # We allow the default value of 32 to maintain compatibility with the function signature,
273
+ # but any other value is invalid since PagedAdamW8bit always uses 8-bit optimization
274
+ raise ValueError("PagedAdamW8bit only supports optim_bits=32 (default value for compatibility)")
275
+
276
+ super().__init__(
277
+ "adam",
278
+ params,
279
+ lr,
280
+ betas,
281
+ eps,
282
+ weight_decay,
283
+ 8, # Hardcoded to 8 bits
284
+ args,
285
+ min_8bit_size,
286
+ is_paged=True,
287
+ )
288
+
289
+
290
+ class PagedAdamW32bit(Optimizer2State):
291
+ def __init__(
292
+ self,
293
+ params,
294
+ lr=1e-3,
295
+ betas=(0.9, 0.999),
296
+ eps=1e-8,
297
+ weight_decay=1e-2,
298
+ amsgrad=False,
299
+ optim_bits=32,
300
+ args=None,
301
+ min_8bit_size=4096,
302
+ ):
303
+ """
304
+ Paged 32-bit AdamW optimizer.
305
+
306
+ Arguments:
307
+ params (`torch.Tensor`):
308
+ The input parameters to optimize.
309
+ lr (`float`, defaults to 1e-3):
310
+ The learning rate.
311
+ betas (`tuple(float, float)`, defaults to (0.9, 0.999)):
312
+ The beta values are the decay rates of the first and second-order moment of the optimizer.
313
+ eps (`float`, defaults to 1e-8):
314
+ The epsilon value prevents division by zero in the optimizer.
315
+ weight_decay (`float`, defaults to 1e-2):
316
+ The weight decay value for the optimizer.
317
+ amsgrad (`bool`, defaults to `False`):
318
+ Whether to use the [AMSGrad](https://hf.co/papers/1904.09237) variant of Adam that uses the maximum of past squared gradients instead.
319
+ optim_bits (`int`, defaults to 32):
320
+ The number of bits of the optimizer state.
321
+ args (`object`, defaults to `None`):
322
+ An object with additional arguments.
323
+ min_8bit_size (`int`, defaults to 4096):
324
+ The minimum number of elements of the parameter tensors for 8-bit optimization.
325
+ """
326
+ super().__init__(
327
+ "adam",
328
+ params,
329
+ lr,
330
+ betas,
331
+ eps,
332
+ weight_decay,
333
+ 32,
334
+ args,
335
+ min_8bit_size,
336
+ is_paged=True,
337
+ )