ThomasHeim commited on
Commit
ec02449
·
verified ·
1 Parent(s): dee56ed

Delete sudoku-extreme/augmented-hrm

Browse files
Files changed (43) hide show
  1. sudoku-extreme/augmented-hrm/all_config.yaml +0 -35
  2. sudoku-extreme/augmented-hrm/hrm_act_v1.py +0 -311
  3. sudoku-extreme/augmented-hrm/losses.py +0 -115
  4. sudoku-extreme/augmented-hrm/step_10416 +0 -3
  5. sudoku-extreme/augmented-hrm/step_11718 +0 -3
  6. sudoku-extreme/augmented-hrm/step_1302 +0 -3
  7. sudoku-extreme/augmented-hrm/step_13020 +0 -3
  8. sudoku-extreme/augmented-hrm/step_14322 +0 -3
  9. sudoku-extreme/augmented-hrm/step_15624 +0 -3
  10. sudoku-extreme/augmented-hrm/step_16926 +0 -3
  11. sudoku-extreme/augmented-hrm/step_18228 +0 -3
  12. sudoku-extreme/augmented-hrm/step_19530 +0 -3
  13. sudoku-extreme/augmented-hrm/step_20832 +0 -3
  14. sudoku-extreme/augmented-hrm/step_22134 +0 -3
  15. sudoku-extreme/augmented-hrm/step_23436 +0 -3
  16. sudoku-extreme/augmented-hrm/step_24738 +0 -3
  17. sudoku-extreme/augmented-hrm/step_2604 +0 -3
  18. sudoku-extreme/augmented-hrm/step_26040 +0 -3
  19. sudoku-extreme/augmented-hrm/step_27342 +0 -3
  20. sudoku-extreme/augmented-hrm/step_28644 +0 -3
  21. sudoku-extreme/augmented-hrm/step_29946 +0 -3
  22. sudoku-extreme/augmented-hrm/step_31248 +0 -3
  23. sudoku-extreme/augmented-hrm/step_32550 +0 -3
  24. sudoku-extreme/augmented-hrm/step_33852 +0 -3
  25. sudoku-extreme/augmented-hrm/step_35154 +0 -3
  26. sudoku-extreme/augmented-hrm/step_36456 +0 -3
  27. sudoku-extreme/augmented-hrm/step_37758 +0 -3
  28. sudoku-extreme/augmented-hrm/step_3906 +0 -3
  29. sudoku-extreme/augmented-hrm/step_39060 +0 -3
  30. sudoku-extreme/augmented-hrm/step_40362 +0 -3
  31. sudoku-extreme/augmented-hrm/step_41664 +0 -3
  32. sudoku-extreme/augmented-hrm/step_42966 +0 -3
  33. sudoku-extreme/augmented-hrm/step_44268 +0 -3
  34. sudoku-extreme/augmented-hrm/step_45570 +0 -3
  35. sudoku-extreme/augmented-hrm/step_46872 +0 -3
  36. sudoku-extreme/augmented-hrm/step_48174 +0 -3
  37. sudoku-extreme/augmented-hrm/step_49476 +0 -3
  38. sudoku-extreme/augmented-hrm/step_50778 +0 -3
  39. sudoku-extreme/augmented-hrm/step_5208 +0 -3
  40. sudoku-extreme/augmented-hrm/step_52080 +0 -3
  41. sudoku-extreme/augmented-hrm/step_6510 +0 -3
  42. sudoku-extreme/augmented-hrm/step_7812 +0 -3
  43. sudoku-extreme/augmented-hrm/step_9114 +0 -3
sudoku-extreme/augmented-hrm/all_config.yaml DELETED
@@ -1,35 +0,0 @@
1
- arch:
2
- H_cycles: 2
3
- H_layers: 4
4
- L_cycles: 2
5
- L_layers: 4
6
- expansion: 4
7
- halt_exploration_prob: 0.1
8
- halt_max_steps: 16
9
- hidden_size: 512
10
- loss:
11
- loss_type: stablemax_cross_entropy
12
- name: losses@ACTLossHead
13
- name: hrm.hrm_act_v1@HierarchicalReasoningModel_ACTV1
14
- num_heads: 8
15
- pos_encodings: rope
16
- puzzle_emb_ndim: 512
17
- beta1: 0.9
18
- beta2: 0.95
19
- checkpoint_every_eval: true
20
- checkpoint_path: checkpoints/Sudoku-extreme-1k-aug-1000-hint ACT-torch/HierarchicalReasoningModel_ACTV1
21
- hopeful-quetzal
22
- data_path: ../../dataset/data/sudoku-extreme-1k-aug-1000-hint
23
- epochs: 40000
24
- eval_interval: 1000
25
- eval_save_outputs: []
26
- global_batch_size: 768
27
- lr: 0.0001
28
- lr_min_ratio: 1.0
29
- lr_warmup_steps: 2000
30
- project_name: Sudoku-extreme-1k-aug-1000-hint ACT-torch
31
- puzzle_emb_lr: 0.0001
32
- puzzle_emb_weight_decay: 1.0
33
- run_name: HierarchicalReasoningModel_ACTV1 hopeful-quetzal
34
- seed: 0
35
- weight_decay: 1.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
sudoku-extreme/augmented-hrm/hrm_act_v1.py DELETED
@@ -1,311 +0,0 @@
1
- from typing import Tuple, List, Dict, Optional
2
- from dataclasses import dataclass
3
- import math
4
-
5
- import torch
6
- import torch.nn.functional as F
7
- from torch import nn
8
- from pydantic import BaseModel
9
-
10
- from models.common import trunc_normal_init_
11
- from models.layers import rms_norm, SwiGLU, Attention, RotaryEmbedding, CosSin, CastedEmbedding, CastedLinear
12
- from models.sparse_embedding import CastedSparseEmbedding
13
-
14
-
15
- @dataclass
16
- class HierarchicalReasoningModel_ACTV1InnerCarry:
17
- z_H: torch.Tensor
18
- z_L: torch.Tensor
19
-
20
-
21
- @dataclass
22
- class HierarchicalReasoningModel_ACTV1Carry:
23
- inner_carry: HierarchicalReasoningModel_ACTV1InnerCarry
24
-
25
- steps: torch.Tensor
26
- halted: torch.Tensor
27
-
28
- current_data: Dict[str, torch.Tensor]
29
-
30
-
31
- class HierarchicalReasoningModel_ACTV1Config(BaseModel):
32
- batch_size: int
33
- seq_len: int
34
- puzzle_emb_ndim: int = 0
35
- num_puzzle_identifiers: int
36
- vocab_size: int
37
-
38
- H_cycles: int
39
- L_cycles: int
40
-
41
- H_layers: int
42
- L_layers: int
43
-
44
- # Transformer config
45
- hidden_size: int
46
- expansion: float
47
- num_heads: int
48
- pos_encodings: str
49
-
50
- rms_norm_eps: float = 1e-5
51
- rope_theta: float = 10000.0
52
-
53
- # Halting Q-learning config
54
- halt_max_steps: int
55
- halt_exploration_prob: float
56
-
57
- forward_dtype: str = "bfloat16"
58
-
59
-
60
- class HierarchicalReasoningModel_ACTV1Block(nn.Module):
61
- def __init__(self, config: HierarchicalReasoningModel_ACTV1Config) -> None:
62
- super().__init__()
63
-
64
- self.self_attn = Attention(
65
- hidden_size=config.hidden_size,
66
- head_dim=config.hidden_size // config.num_heads,
67
- num_heads=config.num_heads,
68
- num_key_value_heads=config.num_heads,
69
- causal=False
70
- )
71
- self.mlp = SwiGLU(
72
- hidden_size=config.hidden_size,
73
- expansion=config.expansion,
74
- )
75
- self.norm_eps = config.rms_norm_eps
76
-
77
- def forward(self, cos_sin: CosSin, hidden_states: torch.Tensor) -> torch.Tensor:
78
- # Post Norm
79
- # Self Attention
80
- hidden_states = rms_norm(hidden_states + self.self_attn(cos_sin=cos_sin, hidden_states=hidden_states), variance_epsilon=self.norm_eps)
81
- # Fully Connected
82
- hidden_states = rms_norm(hidden_states + self.mlp(hidden_states), variance_epsilon=self.norm_eps)
83
- return hidden_states
84
-
85
-
86
- class HierarchicalReasoningModel_ACTV1ReasoningModule(nn.Module):
87
- def __init__(self, layers: List[HierarchicalReasoningModel_ACTV1Block]):
88
- super().__init__()
89
-
90
- self.layers = torch.nn.ModuleList(layers)
91
-
92
- def forward(self, hidden_states: torch.Tensor, input_injection: torch.Tensor, **kwargs) -> torch.Tensor:
93
- # Input injection (add)
94
- hidden_states = hidden_states + input_injection
95
- # Layers
96
- for layer in self.layers:
97
- hidden_states = layer(hidden_states=hidden_states, **kwargs)
98
-
99
- return hidden_states
100
-
101
-
102
- class HierarchicalReasoningModel_ACTV1_Inner(nn.Module):
103
- def __init__(self, config: HierarchicalReasoningModel_ACTV1Config) -> None:
104
- super().__init__()
105
- self.config = config
106
- self.forward_dtype = getattr(torch, self.config.forward_dtype)
107
-
108
- # I/O
109
- self.embed_scale = math.sqrt(self.config.hidden_size)
110
- embed_init_std = 1.0 / self.embed_scale
111
-
112
- self.embed_tokens = CastedEmbedding(self.config.vocab_size, self.config.hidden_size, init_std=embed_init_std, cast_to=self.forward_dtype)
113
- self.lm_head = CastedLinear(self.config.hidden_size, self.config.vocab_size, bias=False)
114
- self.q_head = CastedLinear(self.config.hidden_size, 2, bias=True)
115
-
116
- self.puzzle_emb_len = -(self.config.puzzle_emb_ndim // -self.config.hidden_size) # ceil div
117
- if self.config.puzzle_emb_ndim > 0:
118
- # Zero init puzzle embeddings
119
- self.puzzle_emb = CastedSparseEmbedding(self.config.num_puzzle_identifiers, self.config.puzzle_emb_ndim,
120
- batch_size=self.config.batch_size, init_std=0, cast_to=self.forward_dtype)
121
-
122
- # LM Blocks
123
- if self.config.pos_encodings == "rope":
124
- self.rotary_emb = RotaryEmbedding(dim=self.config.hidden_size // self.config.num_heads,
125
- max_position_embeddings=self.config.seq_len + self.puzzle_emb_len,
126
- base=self.config.rope_theta)
127
- elif self.config.pos_encodings == "learned":
128
- self.embed_pos = CastedEmbedding(self.config.seq_len + self.puzzle_emb_len, self.config.hidden_size, init_std=embed_init_std, cast_to=self.forward_dtype)
129
- else:
130
- raise NotImplementedError()
131
-
132
- # Reasoning Layers
133
- self.H_level = HierarchicalReasoningModel_ACTV1ReasoningModule(layers=[HierarchicalReasoningModel_ACTV1Block(self.config) for _i in range(self.config.H_layers)])
134
- self.L_level = HierarchicalReasoningModel_ACTV1ReasoningModule(layers=[HierarchicalReasoningModel_ACTV1Block(self.config) for _i in range(self.config.L_layers)])
135
-
136
- # Initial states
137
- self.H_init = nn.Buffer(trunc_normal_init_(torch.empty(self.config.hidden_size, dtype=self.forward_dtype), std=1), persistent=True)
138
- self.L_init = nn.Buffer(trunc_normal_init_(torch.empty(self.config.hidden_size, dtype=self.forward_dtype), std=1), persistent=True)
139
-
140
- # Q head special init
141
- # Init Q to (almost) zero for faster learning during bootstrapping
142
- with torch.no_grad():
143
- self.q_head.weight.zero_()
144
- self.q_head.bias.fill_(-5) # type: ignore
145
-
146
- def _input_embeddings(self, input: torch.Tensor, puzzle_identifiers: torch.Tensor):
147
- # Token embedding
148
- embedding = self.embed_tokens(input.to(torch.int32))
149
-
150
- # Puzzle embeddings
151
- if self.config.puzzle_emb_ndim > 0:
152
- puzzle_embedding = self.puzzle_emb(puzzle_identifiers)
153
-
154
- pad_count = self.puzzle_emb_len * self.config.hidden_size - puzzle_embedding.shape[-1]
155
- if pad_count > 0:
156
- puzzle_embedding = F.pad(puzzle_embedding, (0, pad_count))
157
-
158
- embedding = torch.cat((puzzle_embedding.view(-1, self.puzzle_emb_len, self.config.hidden_size), embedding), dim=-2)
159
-
160
- # Position embeddings
161
- if self.config.pos_encodings == "learned":
162
- # scale by 1/sqrt(2) to maintain forward variance
163
- embedding = 0.707106781 * (embedding + self.embed_pos.embedding_weight.to(self.forward_dtype))
164
-
165
- # Scale
166
- return self.embed_scale * embedding
167
-
168
- def empty_carry(self, batch_size: int):
169
- return HierarchicalReasoningModel_ACTV1InnerCarry(
170
- z_H=torch.empty(batch_size, self.config.seq_len + self.puzzle_emb_len, self.config.hidden_size, dtype=self.forward_dtype),
171
- z_L=torch.empty(batch_size, self.config.seq_len + self.puzzle_emb_len, self.config.hidden_size, dtype=self.forward_dtype),
172
- )
173
-
174
- def reset_carry(self, reset_flag: torch.Tensor, carry: HierarchicalReasoningModel_ACTV1InnerCarry, use_default=True):
175
- if use_default:
176
- return HierarchicalReasoningModel_ACTV1InnerCarry(
177
- z_H=torch.where(reset_flag.view(-1, 1, 1), self.H_init, carry.z_H),
178
- z_L=torch.where(reset_flag.view(-1, 1, 1), self.L_init, carry.z_L),
179
- )
180
- else:
181
- H_tmp = trunc_normal_init_(torch.empty(self.config.hidden_size, dtype=self.forward_dtype), std=2).to("cuda")+self.H_init
182
- L_tmp = trunc_normal_init_(torch.empty(self.config.hidden_size, dtype=self.forward_dtype), std=2).to("cuda")+self.L_init
183
- return HierarchicalReasoningModel_ACTV1InnerCarry(
184
- z_H=torch.where(reset_flag.view(-1, 1, 1), H_tmp, carry.z_H),
185
- z_L=torch.where(reset_flag.view(-1, 1, 1), L_tmp, carry.z_L)
186
- )
187
-
188
-
189
- def forward(self, carry: HierarchicalReasoningModel_ACTV1InnerCarry, batch: Dict[str, torch.Tensor], require_trace=False):
190
- # -> Tuple[HierarchicalReasoningModel_ACTV1InnerCarry, torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
191
- seq_info = dict(
192
- cos_sin=self.rotary_emb() if hasattr(self, "rotary_emb") else None,
193
- )
194
-
195
- # Input encoding
196
- input_embeddings = self._input_embeddings(batch["inputs"], batch["puzzle_identifiers"])
197
-
198
- z_H_trace = []
199
-
200
- # Forward iterations
201
- with torch.no_grad():
202
- z_H, z_L = carry.z_H, carry.z_L
203
-
204
- for _H_step in range(self.config.H_cycles):
205
- for _L_step in range(self.config.L_cycles):
206
- if not ((_H_step == self.config.H_cycles - 1) and (_L_step == self.config.L_cycles - 1)):
207
- z_L = self.L_level(z_L, z_H + input_embeddings, **seq_info)
208
-
209
- if not (_H_step == self.config.H_cycles - 1):
210
- z_H = self.H_level(z_H, z_L, **seq_info)
211
- if require_trace:
212
- z_H_trace.append(z_H.detach().cpu().clone())
213
-
214
- assert not z_H.requires_grad and not z_L.requires_grad
215
-
216
- # 1-step grad
217
- z_L = self.L_level(z_L, z_H + input_embeddings, **seq_info)
218
- z_H = self.H_level(z_H, z_L, **seq_info)
219
-
220
- if require_trace:
221
- z_H_trace.append(z_H.detach().cpu().clone())
222
-
223
- # LM Outputs
224
- new_carry = HierarchicalReasoningModel_ACTV1InnerCarry(z_H=z_H.detach(), z_L=z_L.detach()) # New carry no grad
225
- output = self.lm_head(z_H)[:, self.puzzle_emb_len:]
226
-
227
- # Q head
228
- q_logits = self.q_head(z_H[:, 0]).to(torch.float32)
229
-
230
- if require_trace:
231
- return z_H_trace, new_carry, output, (q_logits[..., 0], q_logits[..., 1])
232
- else:
233
- return new_carry, output, (q_logits[..., 0], q_logits[..., 1])
234
-
235
-
236
- class HierarchicalReasoningModel_ACTV1(nn.Module):
237
- """ACT wrapper."""
238
-
239
- def __init__(self, config_dict: dict):
240
- super().__init__()
241
- self.config = HierarchicalReasoningModel_ACTV1Config(**config_dict)
242
- self.inner = HierarchicalReasoningModel_ACTV1_Inner(self.config)
243
-
244
- @property
245
- def puzzle_emb(self):
246
- return self.inner.puzzle_emb
247
-
248
- def initial_carry(self, batch: Dict[str, torch.Tensor]):
249
- batch_size = batch["inputs"].shape[0]
250
-
251
- return HierarchicalReasoningModel_ACTV1Carry(
252
- inner_carry=self.inner.empty_carry(batch_size), # Empty is expected, it will be reseted in first pass as all sequences are halted.
253
-
254
- steps=torch.zeros((batch_size, ), dtype=torch.int32),
255
- halted=torch.ones((batch_size, ), dtype=torch.bool), # Default to halted
256
-
257
- current_data={k: torch.empty_like(v) for k, v in batch.items()}
258
- )
259
-
260
- def forward(self, carry: HierarchicalReasoningModel_ACTV1Carry, batch: Dict[str, torch.Tensor], require_trace=False):
261
- # -> Tuple[HierarchicalReasoningModel_ACTV1Carry, Dict[str, torch.Tensor], torch.Tensor]:
262
- # Update data, carry (removing halted sequences)
263
- new_inner_carry = self.inner.reset_carry(carry.halted, carry.inner_carry)
264
-
265
- new_steps = torch.where(carry.halted, 0, carry.steps)
266
-
267
- new_current_data = {k: torch.where(carry.halted.view((-1, ) + (1, ) * (batch[k].ndim - 1)), batch[k], v) for k, v in carry.current_data.items()}
268
-
269
- # Forward inner model
270
- if require_trace:
271
- z_H_trace, new_inner_carry, logits, (q_halt_logits, q_continue_logits) = self.inner(new_inner_carry, new_current_data, require_trace=require_trace)
272
- else:
273
- new_inner_carry, logits, (q_halt_logits, q_continue_logits) = self.inner(new_inner_carry, new_current_data)
274
-
275
- outputs = {
276
- "logits": logits,
277
- "q_halt_logits": q_halt_logits,
278
- "q_continue_logits": q_continue_logits
279
- }
280
-
281
- with torch.no_grad():
282
- # Step
283
- new_steps = new_steps + 1
284
- is_last_step = new_steps >= self.config.halt_max_steps
285
- # is_last_step = new_steps >= 32
286
-
287
- halted = is_last_step
288
-
289
- # if training, and ACT is enabled
290
- if self.training and (self.config.halt_max_steps > 1):
291
- # Halt signal
292
- # NOTE: During evaluation, always use max steps, this is to guarantee the same halting steps inside a batch for batching purposes
293
- halted = halted | (q_halt_logits > q_continue_logits)
294
-
295
- # Exploration
296
- min_halt_steps = (torch.rand_like(q_halt_logits) < self.config.halt_exploration_prob) * torch.randint_like(new_steps, low=2, high=self.config.halt_max_steps + 1)
297
-
298
- halted = halted & (new_steps >= min_halt_steps)
299
-
300
- # Compute target Q
301
- # NOTE: No replay buffer and target networks for computing target Q-value.
302
- # As batch_size is large, there're many parallel envs.
303
- # Similar concept as PQN https://arxiv.org/abs/2407.04811
304
- next_q_halt_logits, next_q_continue_logits = self.inner(new_inner_carry, new_current_data)[-1]
305
-
306
- outputs["target_q_continue"] = torch.sigmoid(torch.where(is_last_step, next_q_halt_logits, torch.maximum(next_q_halt_logits, next_q_continue_logits)))
307
-
308
- if require_trace:
309
- return HierarchicalReasoningModel_ACTV1Carry(new_inner_carry, new_steps, halted, new_current_data), outputs, new_steps, (q_halt_logits > q_continue_logits), z_H_trace
310
- else:
311
- return HierarchicalReasoningModel_ACTV1Carry(new_inner_carry, new_steps, halted, new_current_data), outputs, new_steps, (q_halt_logits > q_continue_logits)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
sudoku-extreme/augmented-hrm/losses.py DELETED
@@ -1,115 +0,0 @@
1
- from typing import Any, Tuple, Dict, Sequence, Optional
2
-
3
- import torch
4
- import torch.nn.functional as F
5
- from torch import nn
6
-
7
-
8
- IGNORE_LABEL_ID = -100
9
-
10
-
11
- def s(x, epsilon=1e-30):
12
- return torch.where(
13
- x<0,
14
- 1/(1-x+ epsilon),
15
- x + 1
16
- )
17
-
18
-
19
- def log_stablemax(x, dim=-1):
20
- s_x = s(x)
21
- return torch.log(s_x/torch.sum(s_x, dim=dim, keepdim=True))
22
-
23
-
24
- def stablemax_cross_entropy(logits, labels, ignore_index: int = -100):
25
- logprobs = log_stablemax(logits.to(torch.float64), dim=-1)
26
-
27
- valid_mask = labels != ignore_index
28
- transformed_labels = torch.where(valid_mask, labels, 0)
29
- prediction_logprobs = torch.gather(logprobs, index=transformed_labels.to(torch.long).unsqueeze(-1), dim=-1).squeeze(-1)
30
-
31
- return -torch.where(valid_mask, prediction_logprobs, 0)
32
-
33
-
34
- def softmax_cross_entropy(logits, labels, ignore_index: int = -100):
35
- # Cast logits to f32
36
- # Flatten logits
37
- return F.cross_entropy(logits.to(torch.float32).view(-1, logits.shape[-1]), labels.to(torch.long).view(-1), ignore_index=ignore_index, reduction="none").view(labels.shape)
38
-
39
-
40
- class ACTLossHead(nn.Module):
41
- def __init__(self, model: nn.Module, loss_type: str):
42
- super().__init__()
43
- self.model = model
44
- self.loss_fn = globals()[loss_type]
45
-
46
- def initial_carry(self, *args, **kwargs):
47
- return self.model.initial_carry(*args, **kwargs) # type: ignore
48
-
49
- def forward(
50
- self,
51
- return_keys: Sequence[str],
52
- require_trace=False,
53
- # Model args
54
- **model_kwargs,
55
- ) -> Tuple[Any, torch.Tensor, Dict[str, torch.Tensor], Optional[Dict[str, torch.Tensor]], torch.Tensor]:
56
- # Model logits
57
- # B x SeqLen x D
58
- if require_trace:
59
- new_carry, outputs, steps, act_halt, z_H_trace = self.model(**model_kwargs, require_trace=require_trace)
60
- else:
61
- new_carry, outputs, steps, act_halt = self.model(**model_kwargs)
62
- labels = new_carry.current_data["labels"]
63
- alpha = 1.0
64
- ds_mask = (alpha ** (16-steps.detach())).unsqueeze(dim=1)
65
- # print(ds_mask.shape)
66
-
67
- # Correctness
68
- with torch.no_grad():
69
- mask = labels != IGNORE_LABEL_ID
70
- loss_counts = mask.sum(-1)
71
- loss_divisor = loss_counts.clamp_min(1).unsqueeze(-1) # Avoid NaNs in division
72
-
73
- is_correct = mask & (torch.argmax(outputs["logits"], dim=-1) == labels)
74
- seq_is_correct = is_correct.sum(-1) == loss_counts
75
-
76
- # # Metrics (halted)
77
- # valid_metrics = new_carry.halted & (loss_counts > 0)
78
- valid_metrics = (loss_counts > 0)
79
-
80
- metrics = {
81
- "count": valid_metrics.sum(),
82
-
83
- "accuracy": torch.where(valid_metrics, (is_correct.to(torch.float32) / loss_divisor).sum(-1), 0).sum(),
84
- "exact_accuracy": (valid_metrics & seq_is_correct).sum(),
85
-
86
- "q_halt_accuracy": (valid_metrics & ((outputs["q_halt_logits"] >= 0) == seq_is_correct)).sum(),
87
- "steps": torch.where(valid_metrics, new_carry.steps, 0).sum(),
88
- }
89
-
90
- # Losses
91
- # FIXME: Assuming the batch is always full
92
- loss = self.loss_fn(outputs["logits"], labels, ignore_index=IGNORE_LABEL_ID)
93
- # print(loss.shape)
94
- lm_loss = (ds_mask * loss / loss_divisor).sum()
95
- q_halt_loss = F.binary_cross_entropy_with_logits(outputs["q_halt_logits"], seq_is_correct.to(outputs["q_halt_logits"].dtype), reduction="sum")
96
-
97
- metrics.update({
98
- "lm_loss": lm_loss.detach(),
99
- "q_halt_loss": q_halt_loss.detach(),
100
- })
101
-
102
- # Q continue (bootstrapping target loss)
103
- q_continue_loss = 0
104
- if "target_q_continue" in outputs:
105
- q_continue_loss = F.binary_cross_entropy_with_logits(outputs["q_continue_logits"], outputs["target_q_continue"], reduction="sum")
106
-
107
- metrics["q_continue_loss"] = q_continue_loss.detach()
108
-
109
- # Filter outputs for return
110
- detached_outputs = {k: outputs[k].detach() for k in return_keys if k in outputs}
111
-
112
- if require_trace:
113
- return z_H_trace, new_carry, lm_loss + 0.5 * (q_halt_loss + q_continue_loss), metrics, detached_outputs, new_carry.halted.all(), new_carry.halted & act_halt
114
- else:
115
- return new_carry, lm_loss + 0.5 * (q_halt_loss + q_continue_loss), metrics, detached_outputs, new_carry.halted.all(), new_carry.halted & act_halt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
sudoku-extreme/augmented-hrm/step_10416 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:9c58c3f870e01c7b9ea71acd128383eb1121ead36b039ddc527ba99326df4a27
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_11718 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:6b8a17f320bcf07ec9d4de1a8d0700906ac6272bc21645beb495f6e63130e40f
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_1302 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:6b4184cfd2db078c6a51160cb52eb501b5055d4570817a4e35015069afcf2163
3
- size 109124296
 
 
 
 
sudoku-extreme/augmented-hrm/step_13020 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:d897d505722435b39b27df0371df24db25e65b16aa726027741fad22551eeace
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_14322 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:27f34b2a089dc0dfb798ac8a803bb6881e04b812d73f4ccd4caa1403106e635d
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_15624 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:055c2210483f46979a4f3dba036f5849376c4ad94306e238bc20c6bdba9385d5
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_16926 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:0f6c65467f330309d837724f11ef5be112ab15c59153a054d0620d6ce038bd93
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_18228 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:1f09e18eda6656bbf76a1731f1dd83d4ac96cc0289bb6dc61f836d87e2b9744a
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_19530 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:69af9c6808313c91014c3f493a581333c4241288780040f74e027f8011c73da1
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_20832 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:89c400212dbcdf4ad9aad1b8bf2da77a3e0f5f72a97e9f01eebc00bd5c50987f
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_22134 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:9b6664aac34744f87463250d379d2d3fb75eb35229e609b640ea5e744a275f09
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_23436 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:90015d8bf2a1164e7b76445e187b2944343434d40eab16c7adbad65cbbe183c1
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_24738 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:194ef810eeed7c3c6ab47a6dcecd005973d94f64cebaba28b735149672e57bc9
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_2604 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:bc3077865661b89a41f15b9e1d3d7500278eab43681a762557328c3965c9613e
3
- size 109124296
 
 
 
 
sudoku-extreme/augmented-hrm/step_26040 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:822db0d53159ea6e3609e0231145b11644661f137ce154e69932f2799c6fc218
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_27342 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:21d01ac7893b791d776d718d312258ba163e34cb83f79681a3199cb16da3cc7b
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_28644 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:0a4a79b8c9257e519821e9fc2256a2bbee2259a54577f1feda15a5daa0f419af
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_29946 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:62691d4a98c1dbbcfc9df55f3228bf28d9302b97bcfa248bd877227aea5afa04
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_31248 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:907f28224104af1123750c968e6bff566871a5fa3dd0ec2602622ca0cdbb5431
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_32550 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:cd2146110c8af9a8f59144c9e2f1138aa8c8b354e67e4939e2adeb394080a54e
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_33852 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:fbd7dfd484acfa11daa48a0e7df5b97a402dd1891e1a770953dce25ba3212311
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_35154 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:e137a7095ed637f383da29fa51d548d7f8381dd852f15f98bd918c2754cb3472
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_36456 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ddb9bf9d42109d1c13cd6a39c4e86a19555b637c38bf5b992deb6c10bffe4bde
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_37758 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:70e86d638e876d29fdd4b7d07d68460dac779e402a7fda4da137edb73c5b3f79
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_3906 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:2b3bcf655ca6bda5eeababb44b736d4da76a29fbfafc08378248341177b4f29d
3
- size 109124296
 
 
 
 
sudoku-extreme/augmented-hrm/step_39060 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:c2b141ae8fbb6333801e44ea3033e381723a01c513ae5115d13fb1606ea017cb
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_40362 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:85be48ffd29247f0b2955596e40bce1c4d3f426db3ef2f14aaada46cffe64e47
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_41664 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:331ca95e1e69985de2b9585fa3d908084b76d6595330d6701dc6cc722bf5cf5f
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_42966 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:763d083485336726a4d8a8fc96d48efa0f361152f3987b29b00521ddedde7379
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_44268 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:5512a6b339ba9e4f82c32d7715a18b2efb00dbbbe30752e4385be226cb896291
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_45570 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:08fab5e91dbac51dd230c38ff9722f54bab1bcba572eeb2680b5a3dea38c37f3
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_46872 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:c38b064cb860b4010d67bcd436a65074db539eb7650bdabeff6857bbbe101909
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_48174 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ad5637a7444577632c9d940ef28ec6726472bddf0f24885b09697372351711f4
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_49476 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:648b7ae9f110efedff7c9da31afd90953ce1344a08154de5866e4efcfc13d9c8
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_50778 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:60da15d0545b8eaa638c5ed888a7e3a12116a5c575d55b1fb22abb03f2183712
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_5208 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:56a4b69e82b45e38c0c5aaa6dcf4b28109995f6283d2880b4f15e982c713d1e4
3
- size 109124296
 
 
 
 
sudoku-extreme/augmented-hrm/step_52080 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:b83423bb0b263399a72c6259c3527993a427a00792e9efd3e0b0d87c21b6b7d6
3
- size 109124341
 
 
 
 
sudoku-extreme/augmented-hrm/step_6510 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:aba4bd3427b9b524df4fb4d45f757efef72a2b5c40c7ae383c67088f3fc0d0eb
3
- size 109124296
 
 
 
 
sudoku-extreme/augmented-hrm/step_7812 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:4783d7ce493907959a2d82d719103092b69c0f295695f62596dc19368c7ecc76
3
- size 109124296
 
 
 
 
sudoku-extreme/augmented-hrm/step_9114 DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:1d0bae068e1c11e7550f4c59f918abe22a3986b9df995d5282d61541c3633acc
3
- size 109124296