heavyball 0.23.4__tar.gz → 0.24.1__tar.gz

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 (44) hide show
  1. {heavyball-0.23.4 → heavyball-0.24.1}/PKG-INFO +1 -1
  2. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/cached_delayed_psgd_kron.py +1 -1
  3. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/cached_psgd_kron.py +1 -1
  4. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/delayed_psgd.py +1 -1
  5. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/foreach_adamw.py +2 -2
  6. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/foreach_adopt.py +2 -2
  7. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/foreach_laprop.py +2 -2
  8. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/foreach_sfadamw.py +2 -2
  9. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/foreach_soap.py +2 -2
  10. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/p_adam.py +2 -2
  11. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/palm_foreach_sfadamw.py +2 -2
  12. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/palm_foreach_soap.py +2 -2
  13. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/precond_schedule_foreach_soap.py +2 -2
  14. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/precond_schedule_palm_foreach_soap.py +2 -2
  15. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/precond_schedule_sfpsoap.py +2 -2
  16. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/psgd_kron.py +1 -1
  17. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/schedule_free_palm_foreach_soap.py +1 -1
  18. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/utils.py +3 -3
  19. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball.egg-info/PKG-INFO +1 -1
  20. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball.egg-info/SOURCES.txt +1 -0
  21. {heavyball-0.23.4 → heavyball-0.24.1}/setup.py +1 -1
  22. heavyball-0.24.1/test/test_channels_last.py +51 -0
  23. {heavyball-0.23.4 → heavyball-0.24.1}/LICENSE +0 -0
  24. {heavyball-0.23.4 → heavyball-0.24.1}/README.md +0 -0
  25. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/__init__.py +0 -0
  26. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball/pure_psgd.py +0 -0
  27. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball.egg-info/dependency_links.txt +0 -0
  28. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball.egg-info/requires.txt +0 -0
  29. {heavyball-0.23.4 → heavyball-0.24.1}/heavyball.egg-info/top_level.txt +0 -0
  30. {heavyball-0.23.4 → heavyball-0.24.1}/setup.cfg +0 -0
  31. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_bf16_params.py +0 -0
  32. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_bf16_q.py +0 -0
  33. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_bf16_storage.py +0 -0
  34. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_caution.py +0 -0
  35. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_closure.py +0 -0
  36. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_ema.py +0 -0
  37. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_foreach.py +0 -0
  38. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_mars.py +0 -0
  39. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_memory.py +0 -0
  40. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_merge.py +0 -0
  41. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_no_grad.py +0 -0
  42. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_psgd.py +0 -0
  43. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_soap.py +0 -0
  44. {heavyball-0.23.4 → heavyball-0.24.1}/test/test_stochastic_updates.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: heavyball
3
- Version: 0.23.4
3
+ Version: 0.24.1
4
4
  Summary: Efficient optimizers
5
5
  Home-page: https://github.com/clashluke/heavyball
6
6
  Author: Lucas Nestler
@@ -86,7 +86,7 @@ class ForeachCachedDelayedPSGDKron(PSGDBase):
86
86
  state = self.state_(p)
87
87
 
88
88
  if 'Q' not in state:
89
- state["exp_avg"] = torch.zeros_like(g, dtype=storage_dtype)
89
+ state["exp_avg"] = torch.zeros_like(g, dtype=storage_dtype, memory_format=torch.preserve_format)
90
90
  Q, state["exprs"] = init_Q_exprs(p, precond_init_scale, max_size_triangular, min_ndim_triangular,
91
91
  memory_save_mode, dtype=q_dtype)
92
92
  state['Q'] = triu_to_line(Q) if store_triu_as_line else Q
@@ -83,7 +83,7 @@ class ForeachCachedPSGDKron(PSGDBase):
83
83
  state = self.state_(p)
84
84
 
85
85
  if 'Q' not in state:
86
- state["exp_avg"] = torch.zeros_like(g, dtype=storage_dtype)
86
+ state["exp_avg"] = torch.zeros_like(g, dtype=storage_dtype, memory_format=torch.preserve_format)
87
87
  Q, state["exprs"] = init_Q_exprs(p, precond_init_scale, max_size_triangular, min_ndim_triangular,
88
88
  memory_save_mode, dtype=q_dtype)
89
89
  state['Q'] = triu_to_line(Q) if store_triu_as_line else Q
@@ -89,7 +89,7 @@ class ForeachDelayedPSGD(PSGDBase):
89
89
  state = self.state_(p)
90
90
 
91
91
  if 'Q' not in state:
92
- state["exp_avg"] = torch.zeros_like(g, dtype=storage_dtype)
92
+ state["exp_avg"] = torch.zeros_like(g, dtype=storage_dtype, memory_format=torch.preserve_format)
93
93
  Q, state["exprs"] = init_Q_exprs(p, precond_init_scale, max_size_triangular, min_ndim_triangular,
94
94
  memory_save_mode, dtype=q_dtype)
95
95
  state["Q"] = triu_to_line(Q) if store_triu_as_line else Q
@@ -45,8 +45,8 @@ class ForeachAdamW(StatefulOptimizer):
45
45
 
46
46
  for p in active_p:
47
47
  if 'exp_avg' not in self.state_(p):
48
- self.state_(p)['exp_avg'] = torch.zeros_like(p.data, dtype=storage_dtype)
49
- self.state_(p)['exp_avg_sq'] = torch.zeros_like(p.data, dtype=storage_dtype)
48
+ self.state_(p)['exp_avg'] = torch.zeros_like(p.data, dtype=storage_dtype, memory_format=torch.preserve_format)
49
+ self.state_(p)['exp_avg_sq'] = torch.zeros_like(p.data, dtype=storage_dtype, memory_format=torch.preserve_format)
50
50
 
51
51
  y, grad, exp_avg_sq, exp_avg = zip(
52
52
  *[(p.data, p.grad, self.state_(p)['exp_avg_sq'], self.state_(p)['exp_avg']) for p in active_p])
@@ -51,8 +51,8 @@ class ForeachADOPT(StatefulOptimizer):
51
51
 
52
52
  for p in active_p:
53
53
  if 'exp_avg' not in self.state_(p):
54
- self.state_(p)['exp_avg'] = torch.zeros_like(p.data, dtype=storage_dtype)
55
- self.state_(p)['exp_avg_sq'] = torch.zeros_like(p.data, dtype=storage_dtype)
54
+ self.state_(p)['exp_avg'] = torch.zeros_like(p.data, dtype=storage_dtype, memory_format=torch.preserve_format)
55
+ self.state_(p)['exp_avg_sq'] = torch.zeros_like(p.data, dtype=storage_dtype, memory_format=torch.preserve_format)
56
56
 
57
57
  y, grad, exp_avg_sq, exp_avg = zip(
58
58
  *[(p.data, p.grad, self.state_(p)['exp_avg_sq'], self.state_(p)['exp_avg']) for p in active_p])
@@ -47,8 +47,8 @@ class ForeachLaProp(StatefulOptimizer):
47
47
 
48
48
  for p in active_p:
49
49
  if 'exp_avg' not in self.state_(p):
50
- self.state_(p)['exp_avg'] = torch.zeros_like(p.data, dtype=storage_dtype)
51
- self.state_(p)['exp_avg_sq'] = torch.zeros_like(p.data, dtype=storage_dtype)
50
+ self.state_(p)['exp_avg'] = torch.zeros_like(p.data, dtype=storage_dtype, memory_format=torch.preserve_format)
51
+ self.state_(p)['exp_avg_sq'] = torch.zeros_like(p.data, dtype=storage_dtype, memory_format=torch.preserve_format)
52
52
 
53
53
  y, grad, exp_avg_sq, exp_avg = zip(
54
54
  *[(p.data, p.grad, self.state_(p)['exp_avg_sq'], self.state_(p)['exp_avg']) #
@@ -50,8 +50,8 @@ class ForeachSFAdamW(ScheduleFree):
50
50
 
51
51
  for p in active_p:
52
52
  if 'z' not in self.state_(p):
53
- self.state_(p)['z'] = torch.clone(p.data)
54
- self.state_(p)['exp_avg_sq'] = torch.zeros_like(p.data, dtype=storage_dtype)
53
+ self.state_(p)['z'] = torch.clone(p.data, memory_format=torch.preserve_format)
54
+ self.state_(p)['exp_avg_sq'] = torch.zeros_like(p.data, dtype=storage_dtype, memory_format=torch.preserve_format)
55
55
 
56
56
  y, grad, exp_avg_sq, z = zip(*[(p.data, p.grad, self.state_(p)['exp_avg_sq'], self.state_(p)['z']) #
57
57
  for p in active_p])
@@ -48,8 +48,8 @@ class ForeachSOAP(StatefulOptimizer):
48
48
  step = state['step'] = state.get("step", -1) + 1
49
49
 
50
50
  if "exp_avg" not in state:
51
- state["exp_avg"] = torch.zeros_like(g, dtype=torch.float32)
52
- state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32)
51
+ state["exp_avg"] = torch.zeros_like(g, dtype=torch.float32, memory_format=torch.preserve_format)
52
+ state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32, memory_format=torch.preserve_format)
53
53
  init_preconditioner(g, state, max_precond_dim, precondition_1d)
54
54
  update_preconditioner(g, state, max_precond_dim, precondition_1d, 0, True)
55
55
  continue # first step is skipped so that we never use the current gradients in the projection.
@@ -81,8 +81,8 @@ class ForeachPaLMPAdam(PSGDBase):
81
81
  state = self.state_(p)
82
82
 
83
83
  if 'Q' not in state:
84
- state['exp_avg'] = torch.zeros_like(g, dtype=storage_dtype)
85
- state['exp_avg_sq'] = torch.zeros_like(g, dtype=storage_dtype)
84
+ state['exp_avg'] = torch.zeros_like(g, dtype=storage_dtype, memory_format=torch.preserve_format)
85
+ state['exp_avg_sq'] = torch.zeros_like(g, dtype=storage_dtype, memory_format=torch.preserve_format)
86
86
  Q, state["exprs"] = init_Q_exprs(p, precond_init_scale, max_size_triangular, min_ndim_triangular,
87
87
  memory_save_mode, dtype=q_dtype)
88
88
  state['Q'] = triu_to_line(Q) if store_triu_as_line else Q
@@ -54,8 +54,8 @@ class PaLMForeachSFAdamW(ScheduleFree):
54
54
 
55
55
  for p in active_p:
56
56
  if 'z' not in self.state_(p):
57
- self.state_(p)['z'] = torch.clone(p.data)
58
- self.state_(p)['exp_avg_sq'] = torch.zeros_like(p.data, dtype=storage_dtype)
57
+ self.state_(p)['z'] = torch.clone(p.data, memory_format=torch.preserve_format)
58
+ self.state_(p)['exp_avg_sq'] = torch.zeros_like(p.data, dtype=storage_dtype, memory_format=torch.preserve_format)
59
59
 
60
60
  # Decay the first moment running average coefficient
61
61
  beta2 = 1 - (k + 1) ** -group['beta2_scale']
@@ -56,8 +56,8 @@ class PaLMForeachSOAP(StatefulOptimizer):
56
56
  step = state['step'] = state.get("step", -1) + 1
57
57
 
58
58
  if "exp_avg" not in state:
59
- state["exp_avg"] = torch.zeros_like(g, dtype=torch.float32)
60
- state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32)
59
+ state["exp_avg"] = torch.zeros_like(g, dtype=torch.float32, memory_format=torch.preserve_format)
60
+ state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32, memory_format=torch.preserve_format)
61
61
  init_preconditioner(g, state, max_precond_dim, precondition_1d)
62
62
  update_preconditioner(g, state, max_precond_dim, precondition_1d, 0, True)
63
63
  continue # first step is skipped so that we never use the current gradients in the projection.
@@ -50,8 +50,8 @@ class PrecondScheduleForeachSOAP(StatefulOptimizer):
50
50
  step = state['step'] = state.get("step", -1) + 1
51
51
 
52
52
  if "exp_avg" not in state:
53
- state["exp_avg"] = torch.zeros_like(g, dtype=torch.float32)
54
- state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32)
53
+ state["exp_avg"] = torch.zeros_like(g, dtype=torch.float32, memory_format=torch.preserve_format)
54
+ state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32, memory_format=torch.preserve_format)
55
55
  init_preconditioner(g, state, max_precond_dim, precondition_1d)
56
56
  update_preconditioner(g, state, max_precond_dim, precondition_1d, 0, True)
57
57
  continue # first step is skipped so that we never use the current gradients in the projection.
@@ -58,8 +58,8 @@ class PrecondSchedulePaLMForeachSOAP(StatefulOptimizer):
58
58
  step = state['step'] = state.get("step", -1) + 1
59
59
 
60
60
  if "exp_avg" not in state:
61
- state["exp_avg"] = torch.zeros_like(g, dtype=torch.float32)
62
- state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32)
61
+ state["exp_avg"] = torch.zeros_like(g, dtype=torch.float32, memory_format=torch.preserve_format)
62
+ state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32, memory_format=torch.preserve_format)
63
63
  init_preconditioner(g, state, max_precond_dim, precondition_1d)
64
64
  update_preconditioner(g, state, max_precond_dim, precondition_1d, 0, True)
65
65
  continue # first step is skipped so that we never use the current gradients in the projection.
@@ -96,8 +96,8 @@ class PrecondScheduleSFPaLMSOAP(ScheduleFree):
96
96
  state = self.state_(p)
97
97
 
98
98
  if "z" not in state:
99
- state["z"] = torch.clone(p.data)
100
- state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32)
99
+ state["z"] = torch.clone(p.data, memory_format=torch.preserve_format)
100
+ state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32, memory_format=torch.preserve_format)
101
101
  init_preconditioner(g, state, max_precond_dim, precondition_1d)
102
102
  update_preconditioner(g, state, max_precond_dim, precondition_1d, 0, True)
103
103
  continue # first step is skipped so that we never use the current gradients in the projection.
@@ -84,7 +84,7 @@ class ForeachPSGDKron(PSGDBase):
84
84
  state = self.state_(p)
85
85
 
86
86
  if 'Q' not in state:
87
- state["exp_avg"] = torch.zeros_like(g, dtype=storage_dtype)
87
+ state["exp_avg"] = torch.zeros_like(g, dtype=storage_dtype, memory_format=torch.preserve_format)
88
88
  Q, state["exprs"] = init_Q_exprs(p, precond_init_scale, max_size_triangular, min_ndim_triangular,
89
89
  memory_save_mode, dtype=q_dtype)
90
90
  state['Q'] = triu_to_line(Q) if store_triu_as_line else Q
@@ -90,7 +90,7 @@ class SFPaLMForeachSOAP(ScheduleFree):
90
90
 
91
91
  if "z" not in state:
92
92
  state["z"] = torch.clone(p).float()
93
- state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32)
93
+ state["exp_avg_sq"] = torch.zeros_like(g, dtype=torch.float32, memory_format=torch.preserve_format)
94
94
  if mars:
95
95
  state['mars_prev_grad'] = g.clone()
96
96
  init_preconditioner(g, state, max_precond_dim, precondition_1d)
@@ -60,11 +60,11 @@ def warmup(lr: float, step: int, warmup_steps: int):
60
60
  @decorator_knowngood
61
61
  def _compilable_schedule_free_(p: List[Tensor], z: List[Tensor], ckp1: Tensor, grad: List[Tensor], lr: Tensor,
62
62
  beta1: Tensor):
63
- p32, z32, g32 = [promote(x) for x in (p, z, grad)]
63
+ p32, z32, g32 = [list(map(promote, x)) for x in (p, z, grad)]
64
64
  for p_, z_, g_ in zip(p32, z32, g32):
65
65
  p_.lerp_(z_, ckp1)
66
66
  p_.add_(g_, alpha=lr * (beta1 * (1 - ckp1) - 1))
67
- z_.add(g_, alpha=-lr)
67
+ z_.add_(g_, alpha=-lr)
68
68
  copy_stochastic_list_(p, p32)
69
69
  copy_stochastic_list_(z, z32)
70
70
 
@@ -134,7 +134,7 @@ def dim_merger(grad, max_precond_dim, split: bool = False):
134
134
  if curr_shape > 1 or len(new_shape) == 0:
135
135
  new_shape.append(curr_shape)
136
136
 
137
- new_grad = grad.view(new_shape)
137
+ new_grad = grad.reshape(new_shape) # needs to be .reshape() due to channels_last
138
138
  if not split:
139
139
  return new_grad
140
140
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: heavyball
3
- Version: 0.23.4
3
+ Version: 0.24.1
4
4
  Summary: Efficient optimizers
5
5
  Home-page: https://github.com/clashluke/heavyball
6
6
  Author: Lucas Nestler
@@ -29,6 +29,7 @@ test/test_bf16_params.py
29
29
  test/test_bf16_q.py
30
30
  test/test_bf16_storage.py
31
31
  test/test_caution.py
32
+ test/test_channels_last.py
32
33
  test/test_closure.py
33
34
  test/test_ema.py
34
35
  test/test_foreach.py
@@ -10,7 +10,7 @@ setuptools.setup(
10
10
  name='heavyball',
11
11
  license='BSD',
12
12
  description='Efficient optimizers',
13
- version='0.23.4',
13
+ version='0.24.1',
14
14
  long_description=README,
15
15
  url='https://github.com/clashluke/heavyball',
16
16
  packages=setuptools.find_packages(),
@@ -0,0 +1,51 @@
1
+ import os
2
+
3
+ os.environ["TORCH_LOGS"] = "+recompiles"
4
+
5
+ import heavyball
6
+ import heavyball.utils
7
+ import pytest
8
+ import torch
9
+ from benchmark.utils import get_optim
10
+ from heavyball.utils import clean, set_torch
11
+ from torch import nn
12
+ from torch._dynamo import config
13
+
14
+ heavyball.utils.compile_mode = 'default'
15
+ config.cache_size_limit = 128
16
+
17
+
18
+ @pytest.mark.parametrize("opt", heavyball.__all__)
19
+ @pytest.mark.parametrize("size,depth", [(128, 1)])
20
+ def test_foreach(opt, size, depth: int, iterations: int = 32, outer_iterations: int = 1):
21
+ set_torch()
22
+ opt = getattr(heavyball, opt)
23
+
24
+ peaks = []
25
+ losses = []
26
+
27
+ for is_channels_last in [False, True]:
28
+ torch.manual_seed(0x2131290)
29
+ peaks.append([])
30
+ losses.append([])
31
+
32
+ for i in range(outer_iterations):
33
+ model = nn.Sequential(*[nn.Conv2d(size, size, 3) for _ in range(depth)]).cuda()
34
+ if is_channels_last:
35
+ model.to(memory_format=torch.channels_last)
36
+
37
+ o = get_optim(opt, model.parameters(), lr=1e-3, weight_decay=1e-4, warmup_steps=16)
38
+
39
+ for _ in range(iterations):
40
+ loss = model(torch.randn((1024, size, 4, 4), device='cuda')).square().mean()
41
+ loss.backward()
42
+ o.step()
43
+ o.zero_grad()
44
+ losses[-1].append(loss.detach())
45
+
46
+ del model, o
47
+ clean()
48
+
49
+ for i, (l0, l1) in enumerate(zip(*losses)):
50
+ print(i, l0.item(), l1.item())
51
+ assert torch.allclose(l0.float(), l1.float(), rtol=0.1)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes