promote recoverable chck_8M after compute lease
Browse files- .complete.json +14 -0
- config.json +57 -0
- factor_readout.safetensors +3 -0
- model.safetensors +3 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +9 -0
- tolm.py +910 -0
- training_manifest.json +317 -0
.complete.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"files": {
|
| 3 |
+
"config.json": "cd4a568eff5508f4bc35337bb9541868b4bd71e6c0339028d0727781ea712724",
|
| 4 |
+
"factor_readout.safetensors": "aa5d2b7d2fd879a00e87e4b81891ffbad4dc72c3f1391c697fa387be58f6a1b3",
|
| 5 |
+
"model.safetensors": "d6420d184e659340925793e3b9deb224978d2299e90dbbc01a85afa3499575d7",
|
| 6 |
+
"special_tokens_map.json": "2be97b602cd0e4a6c2874cbf03c0d1025b3af5474666da931bc04f6c23a9a39d",
|
| 7 |
+
"tokenizer.json": "2b8d1b3f51c0d8f276a64ea6a69efa50b4d9899780f1b282b4d0dcb7be5bbb0f",
|
| 8 |
+
"tokenizer_config.json": "8f4a998564d87fc85b27652f0b295677a1e03744bf400bfacc342b700cc3653a",
|
| 9 |
+
"tolm.py": "a9c9469b58e93b7f0228e0c00442735bd0304278e549af37fd3766a902bb1d13",
|
| 10 |
+
"training_manifest.json": "318af35cb5e398ae8da228ce9dd35d3a913bd4bc1f647475f21193f641d9d6a2"
|
| 11 |
+
},
|
| 12 |
+
"schema_version": 1,
|
| 13 |
+
"words_seen": 8000000
|
| 14 |
+
}
|
config.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "tolm",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"TOLMForMaskedLM"
|
| 5 |
+
],
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "tolm.TOLMConfig",
|
| 8 |
+
"AutoModel": "tolm.TOLMModel",
|
| 9 |
+
"AutoModelForMaskedLM": "tolm.TOLMForMaskedLM",
|
| 10 |
+
"AutoModelForCausalLM": "tolm.TOLMForCausalLM"
|
| 11 |
+
},
|
| 12 |
+
"vocab_size": 16384,
|
| 13 |
+
"max_seq_len": 512,
|
| 14 |
+
"hidden_size": 384,
|
| 15 |
+
"num_hidden_layers": 12,
|
| 16 |
+
"num_attention_heads": 6,
|
| 17 |
+
"intermediate_size": 1280,
|
| 18 |
+
"position_buckets": 32,
|
| 19 |
+
"dropout": 0.1,
|
| 20 |
+
"attention_dropout": 0.1,
|
| 21 |
+
"initializer_range": 0.03227486121839514,
|
| 22 |
+
"value_gating": true,
|
| 23 |
+
"residual_mixing": true,
|
| 24 |
+
"pad_token_id": 3,
|
| 25 |
+
"bos_token_id": 1,
|
| 26 |
+
"eos_token_id": 2,
|
| 27 |
+
"mask_token_id": 4,
|
| 28 |
+
"absolute_positions": false,
|
| 29 |
+
"use_rope": false,
|
| 30 |
+
"use_alibi": false,
|
| 31 |
+
"recurrent_steps": 1,
|
| 32 |
+
"num_experts": 1,
|
| 33 |
+
"experts_per_token": 1,
|
| 34 |
+
"expert_intermediate_size": null,
|
| 35 |
+
"future_offsets": [],
|
| 36 |
+
"state_mixer_kernel": 0,
|
| 37 |
+
"rtd_auxiliary": true,
|
| 38 |
+
"geometry_lexical_dim": 0,
|
| 39 |
+
"geometry_curvature": 1.0,
|
| 40 |
+
"cognitive_readout_layer": 0,
|
| 41 |
+
"cognitive_readout_weight": 0.0,
|
| 42 |
+
"direct_sum_dims": [],
|
| 43 |
+
"direct_sum_heads": [],
|
| 44 |
+
"direct_sum_intermediate_sizes": [],
|
| 45 |
+
"lexical_residual_buckets": 0,
|
| 46 |
+
"lexical_residual_dim": 0,
|
| 47 |
+
"lexical_residual_scale": 1.0,
|
| 48 |
+
"structured_projection_dim": 0,
|
| 49 |
+
"factor_readout_mode": "oblique",
|
| 50 |
+
"factor_readout_dims": [
|
| 51 |
+
128,
|
| 52 |
+
128,
|
| 53 |
+
128
|
| 54 |
+
],
|
| 55 |
+
"factor_readout_reflectors": 384,
|
| 56 |
+
"factor_readout_seed": 314159
|
| 57 |
+
}
|
factor_readout.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aa5d2b7d2fd879a00e87e4b81891ffbad4dc72c3f1391c697fa387be58f6a1b3
|
| 3 |
+
size 2064408
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d6420d184e659340925793e3b9deb224978d2299e90dbbc01a85afa3499575d7
|
| 3 |
+
size 133365608
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<s>",
|
| 3 |
+
"eos_token": "</s>",
|
| 4 |
+
"mask_token": "<mask>",
|
| 5 |
+
"pad_token": "<pad>",
|
| 6 |
+
"unk_token": "<unk>"
|
| 7 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<s>",
|
| 3 |
+
"eos_token": "</s>",
|
| 4 |
+
"mask_token": "<mask>",
|
| 5 |
+
"model_max_length": 512,
|
| 6 |
+
"pad_token": "<pad>",
|
| 7 |
+
"tokenizer_class": "PreTrainedTokenizerFast",
|
| 8 |
+
"unk_token": "<unk>"
|
| 9 |
+
}
|
tolm.py
ADDED
|
@@ -0,0 +1,910 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import copy
|
| 2 |
+
import math
|
| 3 |
+
|
| 4 |
+
import torch
|
| 5 |
+
from torch import nn
|
| 6 |
+
from torch.nn import functional as F
|
| 7 |
+
from transformers import PretrainedConfig, PreTrainedModel
|
| 8 |
+
from transformers.modeling_outputs import (
|
| 9 |
+
BaseModelOutput,
|
| 10 |
+
CausalLMOutput,
|
| 11 |
+
MaskedLMOutput,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class TOLMConfig(PretrainedConfig):
|
| 16 |
+
model_type = "tolm"
|
| 17 |
+
|
| 18 |
+
def __init__(
|
| 19 |
+
self,
|
| 20 |
+
vocab_size=16000,
|
| 21 |
+
max_seq_len=512,
|
| 22 |
+
max_position_embeddings=None,
|
| 23 |
+
hidden_size=256,
|
| 24 |
+
num_hidden_layers=4,
|
| 25 |
+
num_attention_heads=4,
|
| 26 |
+
intermediate_size=1024,
|
| 27 |
+
position_buckets=32,
|
| 28 |
+
dropout=0.1,
|
| 29 |
+
hidden_dropout_prob=None,
|
| 30 |
+
attention_dropout=0.1,
|
| 31 |
+
attention_probs_dropout_prob=None,
|
| 32 |
+
initializer_range=0.03952847075210474,
|
| 33 |
+
layer_norm_eps=1.0e-5,
|
| 34 |
+
lm_head_gelu_approximate="tanh",
|
| 35 |
+
shared_relative_embeddings=False,
|
| 36 |
+
feedforward_dropout_after_projection=False,
|
| 37 |
+
attention_output_dropout=False,
|
| 38 |
+
embedding_padding_idx=True,
|
| 39 |
+
value_gating=True,
|
| 40 |
+
residual_mixing=True,
|
| 41 |
+
pad_token_id=1,
|
| 42 |
+
bos_token_id=2,
|
| 43 |
+
eos_token_id=3,
|
| 44 |
+
mask_token_id=4,
|
| 45 |
+
absolute_positions=False,
|
| 46 |
+
use_rope=False,
|
| 47 |
+
use_alibi=False,
|
| 48 |
+
recurrent_steps=1,
|
| 49 |
+
num_experts=1,
|
| 50 |
+
experts_per_token=1,
|
| 51 |
+
expert_intermediate_size=None,
|
| 52 |
+
future_offsets=None,
|
| 53 |
+
state_mixer_kernel=0,
|
| 54 |
+
geometry_lexical_dim=0,
|
| 55 |
+
geometry_curvature=1.0,
|
| 56 |
+
cognitive_readout_layer=0,
|
| 57 |
+
cognitive_readout_weight=0.0,
|
| 58 |
+
direct_sum_dims=None,
|
| 59 |
+
direct_sum_heads=None,
|
| 60 |
+
direct_sum_intermediate_sizes=None,
|
| 61 |
+
lexical_residual_buckets=0,
|
| 62 |
+
lexical_residual_dim=0,
|
| 63 |
+
lexical_residual_scale=1.0,
|
| 64 |
+
structured_projection_dim=0,
|
| 65 |
+
**kwargs,
|
| 66 |
+
):
|
| 67 |
+
super().__init__(
|
| 68 |
+
pad_token_id=pad_token_id,
|
| 69 |
+
bos_token_id=bos_token_id,
|
| 70 |
+
eos_token_id=eos_token_id,
|
| 71 |
+
mask_token_id=mask_token_id,
|
| 72 |
+
**kwargs,
|
| 73 |
+
)
|
| 74 |
+
self.vocab_size = vocab_size
|
| 75 |
+
self.max_seq_len = max_position_embeddings or max_seq_len
|
| 76 |
+
self.max_position_embeddings = self.max_seq_len
|
| 77 |
+
self.hidden_size = hidden_size
|
| 78 |
+
self.num_hidden_layers = num_hidden_layers
|
| 79 |
+
self.num_attention_heads = num_attention_heads
|
| 80 |
+
self.intermediate_size = intermediate_size
|
| 81 |
+
self.position_buckets = position_buckets
|
| 82 |
+
self.dropout = (
|
| 83 |
+
hidden_dropout_prob if hidden_dropout_prob is not None else dropout
|
| 84 |
+
)
|
| 85 |
+
self.hidden_dropout_prob = self.dropout
|
| 86 |
+
self.attention_dropout = (
|
| 87 |
+
attention_probs_dropout_prob
|
| 88 |
+
if attention_probs_dropout_prob is not None
|
| 89 |
+
else attention_dropout
|
| 90 |
+
)
|
| 91 |
+
self.attention_probs_dropout_prob = self.attention_dropout
|
| 92 |
+
self.initializer_range = initializer_range
|
| 93 |
+
self.layer_norm_eps = layer_norm_eps
|
| 94 |
+
self.lm_head_gelu_approximate = lm_head_gelu_approximate
|
| 95 |
+
self.shared_relative_embeddings = shared_relative_embeddings
|
| 96 |
+
self.feedforward_dropout_after_projection = (
|
| 97 |
+
feedforward_dropout_after_projection
|
| 98 |
+
)
|
| 99 |
+
self.attention_output_dropout = attention_output_dropout
|
| 100 |
+
self.embedding_padding_idx = embedding_padding_idx
|
| 101 |
+
self.value_gating = value_gating
|
| 102 |
+
self.residual_mixing = residual_mixing
|
| 103 |
+
self.absolute_positions = absolute_positions
|
| 104 |
+
self.use_rope = use_rope
|
| 105 |
+
self.use_alibi = use_alibi
|
| 106 |
+
self.recurrent_steps = recurrent_steps
|
| 107 |
+
self.num_experts = num_experts
|
| 108 |
+
self.experts_per_token = experts_per_token
|
| 109 |
+
self.expert_intermediate_size = expert_intermediate_size
|
| 110 |
+
self.future_offsets = future_offsets or []
|
| 111 |
+
self.state_mixer_kernel = state_mixer_kernel
|
| 112 |
+
self.geometry_lexical_dim = geometry_lexical_dim
|
| 113 |
+
self.geometry_curvature = geometry_curvature
|
| 114 |
+
self.cognitive_readout_layer = cognitive_readout_layer
|
| 115 |
+
self.cognitive_readout_weight = cognitive_readout_weight
|
| 116 |
+
self.direct_sum_dims = direct_sum_dims or []
|
| 117 |
+
self.direct_sum_heads = direct_sum_heads or []
|
| 118 |
+
self.direct_sum_intermediate_sizes = direct_sum_intermediate_sizes or []
|
| 119 |
+
self.lexical_residual_buckets = lexical_residual_buckets
|
| 120 |
+
self.lexical_residual_dim = lexical_residual_dim
|
| 121 |
+
self.lexical_residual_scale = lexical_residual_scale
|
| 122 |
+
self.structured_projection_dim = structured_projection_dim
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _valid_tokens(input_ids, attention_mask):
|
| 126 |
+
if attention_mask is None:
|
| 127 |
+
return torch.ones_like(input_ids, dtype=torch.bool)
|
| 128 |
+
return attention_mask.to(torch.bool)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def _bidirectional_mask(valid):
|
| 132 |
+
return valid[:, None, None, :] & valid[:, None, :, None]
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _causal_mask(valid):
|
| 136 |
+
length = valid.size(1)
|
| 137 |
+
causal = torch.ones((length, length), dtype=torch.bool, device=valid.device).tril()
|
| 138 |
+
return _bidirectional_mask(valid) & causal[None, None, :, :]
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
class RotaryPositionEncoding(nn.Module):
|
| 142 |
+
def __init__(self, head_width, max_length, *, base=10_000.0):
|
| 143 |
+
super().__init__()
|
| 144 |
+
if head_width % 2:
|
| 145 |
+
raise ValueError("RoPE head width must be even")
|
| 146 |
+
inv_freq = 1.0 / (
|
| 147 |
+
base ** (torch.arange(0, head_width, 2, dtype=torch.float32) / head_width)
|
| 148 |
+
)
|
| 149 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 150 |
+
frequencies = self._frequencies(max_length, inv_freq.device)
|
| 151 |
+
self.register_buffer("cos", frequencies.cos(), persistent=False)
|
| 152 |
+
self.register_buffer("sin", frequencies.sin(), persistent=False)
|
| 153 |
+
|
| 154 |
+
def _frequencies(self, length, device):
|
| 155 |
+
positions = torch.arange(length, dtype=torch.float32, device=device)
|
| 156 |
+
return torch.outer(positions, self.inv_freq.to(device=device))
|
| 157 |
+
|
| 158 |
+
def _rotate(self, value):
|
| 159 |
+
length = value.size(-2)
|
| 160 |
+
if length > self.cos.size(0):
|
| 161 |
+
frequencies = self._frequencies(length, value.device)
|
| 162 |
+
self.cos = frequencies.cos()
|
| 163 |
+
self.sin = frequencies.sin()
|
| 164 |
+
even, odd = value[..., 0::2], value[..., 1::2]
|
| 165 |
+
cos = self.cos[:length].to(device=value.device, dtype=value.dtype)
|
| 166 |
+
sin = self.sin[:length].to(device=value.device, dtype=value.dtype)
|
| 167 |
+
rotated = torch.stack((even * cos - odd * sin, even * sin + odd * cos), dim=-1)
|
| 168 |
+
return rotated.flatten(-2)
|
| 169 |
+
|
| 170 |
+
def encode(self, query, key):
|
| 171 |
+
return self._rotate(query), self._rotate(key)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
class RelativeLogBucketSelfAttention(nn.Module):
|
| 175 |
+
def __init__(self, config):
|
| 176 |
+
super().__init__()
|
| 177 |
+
self.n_heads = config.num_attention_heads
|
| 178 |
+
self.d_head = config.hidden_size // config.num_attention_heads
|
| 179 |
+
self.max_seq_len = config.max_seq_len
|
| 180 |
+
self.buckets = config.position_buckets
|
| 181 |
+
self.value_gating = config.value_gating
|
| 182 |
+
self.use_rope = config.use_rope
|
| 183 |
+
self.use_alibi = config.use_alibi
|
| 184 |
+
self.shared_relative_embeddings = config.shared_relative_embeddings
|
| 185 |
+
self.attention_output_dropout = config.attention_output_dropout
|
| 186 |
+
if self.use_rope and self.use_alibi:
|
| 187 |
+
raise ValueError("RoPE and ALiBi are mutually exclusive")
|
| 188 |
+
self.qk = nn.Linear(config.hidden_size, 2 * config.hidden_size)
|
| 189 |
+
self.value = nn.Linear(
|
| 190 |
+
config.hidden_size,
|
| 191 |
+
2 * config.hidden_size if config.value_gating else config.hidden_size,
|
| 192 |
+
)
|
| 193 |
+
self.out = nn.Linear(config.hidden_size, config.hidden_size)
|
| 194 |
+
self.dropout = nn.Dropout(config.attention_dropout)
|
| 195 |
+
self.relative_embedding = (
|
| 196 |
+
None
|
| 197 |
+
if self.use_rope or self.use_alibi or self.shared_relative_embeddings
|
| 198 |
+
else nn.Parameter(
|
| 199 |
+
torch.empty(2 * config.position_buckets - 1, config.hidden_size)
|
| 200 |
+
)
|
| 201 |
+
)
|
| 202 |
+
self.relative_norm = (
|
| 203 |
+
None
|
| 204 |
+
if self.relative_embedding is None
|
| 205 |
+
else nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
| 206 |
+
)
|
| 207 |
+
self.value_gate_norm = (
|
| 208 |
+
nn.LayerNorm(
|
| 209 |
+
config.hidden_size,
|
| 210 |
+
eps=config.layer_norm_eps,
|
| 211 |
+
elementwise_affine=False,
|
| 212 |
+
)
|
| 213 |
+
if config.value_gating
|
| 214 |
+
else None
|
| 215 |
+
)
|
| 216 |
+
self.rope = (
|
| 217 |
+
RotaryPositionEncoding(self.d_head, config.max_seq_len)
|
| 218 |
+
if config.use_rope
|
| 219 |
+
else None
|
| 220 |
+
)
|
| 221 |
+
self.scale = 1.0 / math.sqrt(
|
| 222 |
+
self.d_head if config.use_rope or config.use_alibi else 3.0 * self.d_head
|
| 223 |
+
)
|
| 224 |
+
if self.relative_embedding is not None:
|
| 225 |
+
nn.init.trunc_normal_(
|
| 226 |
+
self.relative_embedding,
|
| 227 |
+
mean=0.0,
|
| 228 |
+
std=config.initializer_range,
|
| 229 |
+
a=-2 * config.initializer_range,
|
| 230 |
+
b=2 * config.initializer_range,
|
| 231 |
+
)
|
| 232 |
+
self.register_buffer(
|
| 233 |
+
"position_indices",
|
| 234 |
+
self._position_indices(config.max_seq_len, torch.device("cpu")),
|
| 235 |
+
persistent=False,
|
| 236 |
+
)
|
| 237 |
+
self.register_buffer(
|
| 238 |
+
"alibi_bias",
|
| 239 |
+
self._alibi_bias(config.max_seq_len, torch.device("cpu")),
|
| 240 |
+
persistent=False,
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
def _alibi_bias(self, length, device):
|
| 244 |
+
positions = torch.arange(length, device=device)
|
| 245 |
+
distance = (positions[:, None] - positions[None, :]).abs().float()
|
| 246 |
+
slopes = torch.pow(
|
| 247 |
+
2.0,
|
| 248 |
+
-8.0
|
| 249 |
+
* (torch.arange(self.n_heads, device=device).float() + 1.0)
|
| 250 |
+
/ self.n_heads,
|
| 251 |
+
)
|
| 252 |
+
return -slopes[None, :, None, None] * distance[None, None, :, :]
|
| 253 |
+
|
| 254 |
+
def _position_indices(self, length, device):
|
| 255 |
+
positions = torch.arange(length, device=device)
|
| 256 |
+
relative = positions[:, None] - positions[None, :]
|
| 257 |
+
sign = torch.sign(relative)
|
| 258 |
+
half = self.buckets // 2
|
| 259 |
+
absolute = relative.abs().clamp(max=max(half + 1, self.max_seq_len - 1))
|
| 260 |
+
near = absolute <= half
|
| 261 |
+
safe = absolute.clamp_min(half)
|
| 262 |
+
denominator = math.log(max((self.max_seq_len - 1) / half, 1.0001))
|
| 263 |
+
logged = (
|
| 264 |
+
torch.ceil(torch.log(safe / half) / denominator * (half - 1)).long() + half
|
| 265 |
+
)
|
| 266 |
+
bucketed = torch.where(near, relative, logged * sign)
|
| 267 |
+
return (
|
| 268 |
+
bucketed.long().clamp(-self.buckets + 1, self.buckets - 1)
|
| 269 |
+
+ self.buckets
|
| 270 |
+
- 1
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
def forward(self, x, mask, relative_embedding=None):
|
| 274 |
+
batch, length, width = x.shape
|
| 275 |
+
if length > self.position_indices.size(0):
|
| 276 |
+
self.position_indices = self._position_indices(length, x.device)
|
| 277 |
+
q, k = self.qk(x).chunk(2, dim=-1)
|
| 278 |
+
if self.value_gating:
|
| 279 |
+
v, gate = self.value(x).chunk(2, dim=-1)
|
| 280 |
+
gate = F.gelu(gate)
|
| 281 |
+
else:
|
| 282 |
+
v, gate = self.value(x), None
|
| 283 |
+
q = q.view(batch, length, self.n_heads, self.d_head).transpose(1, 2)
|
| 284 |
+
k = k.view(batch, length, self.n_heads, self.d_head).transpose(1, 2)
|
| 285 |
+
v = v.view(batch, length, self.n_heads, self.d_head).transpose(1, 2)
|
| 286 |
+
|
| 287 |
+
if self.rope is not None:
|
| 288 |
+
q, k = self.rope.encode(q, k)
|
| 289 |
+
scores = torch.matmul(q, k.transpose(-2, -1)) * self.scale
|
| 290 |
+
elif self.use_alibi:
|
| 291 |
+
if length > self.alibi_bias.size(-1):
|
| 292 |
+
self.alibi_bias = self._alibi_bias(length, x.device)
|
| 293 |
+
scores = torch.matmul(q, k.transpose(-2, -1)) * self.scale
|
| 294 |
+
scores = scores + self.alibi_bias[:, :, :length, :length].to(
|
| 295 |
+
device=x.device, dtype=scores.dtype
|
| 296 |
+
)
|
| 297 |
+
else:
|
| 298 |
+
if relative_embedding is None:
|
| 299 |
+
assert self.relative_embedding is not None
|
| 300 |
+
assert self.relative_norm is not None
|
| 301 |
+
relative_embedding = self.relative_norm(self.relative_embedding)
|
| 302 |
+
relative = self.qk(self.dropout(relative_embedding))
|
| 303 |
+
relative = relative[self.position_indices[:length, :length].to(x.device)]
|
| 304 |
+
q_pos, k_pos = relative.chunk(2, dim=-1)
|
| 305 |
+
q_pos = q_pos.view(length, length, self.n_heads, self.d_head)
|
| 306 |
+
k_pos = k_pos.view(length, length, self.n_heads, self.d_head)
|
| 307 |
+
scores = torch.matmul(q, k.transpose(-2, -1)) * self.scale
|
| 308 |
+
scores = scores + torch.einsum("bhqd,qkhd->bhqk", q, k_pos) * self.scale
|
| 309 |
+
scores = scores + torch.einsum("bhkd,qkhd->bhqk", k, q_pos) * self.scale
|
| 310 |
+
|
| 311 |
+
probs = torch.softmax(
|
| 312 |
+
scores.masked_fill(~mask, torch.finfo(scores.dtype).min), dim=-1
|
| 313 |
+
)
|
| 314 |
+
probs = self.dropout(probs) if self.training else probs
|
| 315 |
+
output = (
|
| 316 |
+
torch.matmul(probs, v)
|
| 317 |
+
.transpose(1, 2)
|
| 318 |
+
.contiguous()
|
| 319 |
+
.view(batch, length, width)
|
| 320 |
+
)
|
| 321 |
+
if gate is not None and self.value_gate_norm is not None:
|
| 322 |
+
output = self.value_gate_norm(output * gate)
|
| 323 |
+
output = self.out(output)
|
| 324 |
+
return self.dropout(output) if self.attention_output_dropout else output
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
class GeGLU(nn.Module):
|
| 328 |
+
def __init__(self, config, width=None):
|
| 329 |
+
super().__init__()
|
| 330 |
+
width = width or config.intermediate_size
|
| 331 |
+
self.up = nn.Linear(config.hidden_size, 2 * width, bias=False)
|
| 332 |
+
self.post_activation_norm = nn.LayerNorm(
|
| 333 |
+
width, eps=config.layer_norm_eps, elementwise_affine=False
|
| 334 |
+
)
|
| 335 |
+
self.down = nn.Linear(width, config.hidden_size, bias=False)
|
| 336 |
+
self.dropout = nn.Dropout(config.dropout)
|
| 337 |
+
self.dropout_after_projection = config.feedforward_dropout_after_projection
|
| 338 |
+
|
| 339 |
+
def forward(self, x):
|
| 340 |
+
value, gate = self.up(x).chunk(2, dim=-1)
|
| 341 |
+
hidden = value * F.gelu(gate, approximate="tanh")
|
| 342 |
+
hidden = self.post_activation_norm(hidden)
|
| 343 |
+
if self.dropout_after_projection:
|
| 344 |
+
return self.dropout(self.down(hidden))
|
| 345 |
+
return self.down(self.dropout(hidden))
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
class RoutedGeGLU(nn.Module):
|
| 349 |
+
def __init__(self, config):
|
| 350 |
+
super().__init__()
|
| 351 |
+
if not 1 <= config.experts_per_token <= config.num_experts:
|
| 352 |
+
raise ValueError("experts_per_token must be in [1, num_experts]")
|
| 353 |
+
width = config.expert_intermediate_size or max(
|
| 354 |
+
1, config.intermediate_size // config.num_experts
|
| 355 |
+
)
|
| 356 |
+
self.top_k = config.experts_per_token
|
| 357 |
+
self.router = nn.Linear(config.hidden_size, config.num_experts, bias=False)
|
| 358 |
+
self.experts = nn.ModuleList(
|
| 359 |
+
GeGLU(config, width) for _ in range(config.num_experts)
|
| 360 |
+
)
|
| 361 |
+
|
| 362 |
+
def forward(self, x):
|
| 363 |
+
probabilities = self.router(x).softmax(dim=-1)
|
| 364 |
+
weights, indices = probabilities.topk(self.top_k, dim=-1)
|
| 365 |
+
weights = weights / weights.sum(dim=-1, keepdim=True).clamp_min(1e-8)
|
| 366 |
+
gates = torch.zeros_like(probabilities).scatter(-1, indices, weights)
|
| 367 |
+
outputs = torch.stack([expert(x) for expert in self.experts], dim=-2)
|
| 368 |
+
return (outputs * gates.unsqueeze(-1)).sum(dim=-2)
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
class CausalStateMixer(nn.Module):
|
| 372 |
+
def __init__(self, config):
|
| 373 |
+
super().__init__()
|
| 374 |
+
kernel = int(config.state_mixer_kernel)
|
| 375 |
+
self.input = nn.Linear(config.hidden_size, 2 * config.hidden_size, bias=False)
|
| 376 |
+
self.state = nn.Conv1d(
|
| 377 |
+
config.hidden_size,
|
| 378 |
+
config.hidden_size,
|
| 379 |
+
kernel,
|
| 380 |
+
groups=config.hidden_size,
|
| 381 |
+
padding=kernel - 1,
|
| 382 |
+
bias=False,
|
| 383 |
+
)
|
| 384 |
+
self.output = nn.Linear(config.hidden_size, config.hidden_size, bias=False)
|
| 385 |
+
self.gate = nn.Parameter(torch.tensor(-2.0))
|
| 386 |
+
|
| 387 |
+
def forward(self, hidden):
|
| 388 |
+
value, gate = self.input(hidden).chunk(2, dim=-1)
|
| 389 |
+
state = self.state(value.transpose(1, 2))[..., : hidden.size(1)].transpose(1, 2)
|
| 390 |
+
return self.output(state * F.silu(gate)) * self.gate.sigmoid()
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
class DynamicWeightedAverage(nn.Module):
|
| 394 |
+
def __init__(self, n_sublayers):
|
| 395 |
+
super().__init__()
|
| 396 |
+
self.alphas = nn.ParameterList(
|
| 397 |
+
nn.Parameter(torch.cat([torch.zeros(i + 1), torch.ones(1)]))
|
| 398 |
+
for i in range(int(n_sublayers))
|
| 399 |
+
)
|
| 400 |
+
self._states = None
|
| 401 |
+
|
| 402 |
+
def initialize(self, hidden):
|
| 403 |
+
self._states = [hidden]
|
| 404 |
+
|
| 405 |
+
def forward(self, hidden, sublayer_index):
|
| 406 |
+
self._states.append(hidden)
|
| 407 |
+
return torch.tensordot(
|
| 408 |
+
self.alphas[sublayer_index], torch.stack(self._states), dims=1
|
| 409 |
+
)
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
class GPTBertBlock(nn.Module):
|
| 413 |
+
def __init__(self, config):
|
| 414 |
+
super().__init__()
|
| 415 |
+
self.attention_norm = nn.LayerNorm(
|
| 416 |
+
config.hidden_size,
|
| 417 |
+
eps=config.layer_norm_eps,
|
| 418 |
+
elementwise_affine=False,
|
| 419 |
+
)
|
| 420 |
+
self.attention = RelativeLogBucketSelfAttention(config)
|
| 421 |
+
self.state_mixer = (
|
| 422 |
+
CausalStateMixer(config) if config.state_mixer_kernel else None
|
| 423 |
+
)
|
| 424 |
+
self.feedforward_norm = nn.LayerNorm(
|
| 425 |
+
config.hidden_size,
|
| 426 |
+
eps=config.layer_norm_eps,
|
| 427 |
+
elementwise_affine=False,
|
| 428 |
+
)
|
| 429 |
+
self.feedforward = (
|
| 430 |
+
RoutedGeGLU(config) if config.num_experts > 1 else GeGLU(config)
|
| 431 |
+
)
|
| 432 |
+
|
| 433 |
+
def attend(self, hidden, mask, relative_embedding=None):
|
| 434 |
+
normalized = self.attention_norm(hidden)
|
| 435 |
+
attention = self.attention(normalized, mask, relative_embedding)
|
| 436 |
+
return (
|
| 437 |
+
attention
|
| 438 |
+
if self.state_mixer is None
|
| 439 |
+
else attention + self.state_mixer(normalized)
|
| 440 |
+
)
|
| 441 |
+
|
| 442 |
+
def transform(self, hidden):
|
| 443 |
+
return self.feedforward(self.feedforward_norm(hidden))
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
class LexicalResidualEmbedding(nn.Module):
|
| 447 |
+
def __init__(self, config):
|
| 448 |
+
super().__init__()
|
| 449 |
+
buckets = int(config.lexical_residual_buckets)
|
| 450 |
+
width = int(config.lexical_residual_dim) or config.hidden_size
|
| 451 |
+
self.buckets = buckets
|
| 452 |
+
self.pad_token_id = config.pad_token_id
|
| 453 |
+
self.scale = float(config.lexical_residual_scale)
|
| 454 |
+
self.embedding = nn.Embedding(buckets, width, padding_idx=0)
|
| 455 |
+
self.projection = (
|
| 456 |
+
nn.Identity()
|
| 457 |
+
if width == config.hidden_size
|
| 458 |
+
else nn.Linear(width, config.hidden_size, bias=False)
|
| 459 |
+
)
|
| 460 |
+
self.register_buffer(
|
| 461 |
+
"word_start_vocab_mask",
|
| 462 |
+
torch.zeros(config.vocab_size, dtype=torch.bool),
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
def forward(self, token_ids):
|
| 466 |
+
batch, length = token_ids.shape
|
| 467 |
+
positions = torch.arange(length, device=token_ids.device).expand(batch, -1)
|
| 468 |
+
starts = self.word_start_vocab_mask[token_ids].clone()
|
| 469 |
+
starts[:, 0] = True
|
| 470 |
+
start_positions = torch.where(starts, positions, 0).cummax(dim=1).values
|
| 471 |
+
relative = positions - start_positions
|
| 472 |
+
ordinal = relative.long() + 1
|
| 473 |
+
mixed = (token_ids.long() + 1) * ordinal * 1_000_003 + ordinal * 97_409
|
| 474 |
+
cumulative = mixed.cumsum(dim=1)
|
| 475 |
+
before = F.pad(cumulative[:, :-1], (1, 0))
|
| 476 |
+
prefix_hashes = cumulative - before.gather(1, start_positions)
|
| 477 |
+
buckets = prefix_hashes.remainder(self.buckets - 1) + 1
|
| 478 |
+
buckets = buckets.masked_fill(token_ids.eq(self.pad_token_id), 0)
|
| 479 |
+
return self.scale * self.projection(self.embedding(buckets))
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
class GPTBertBackbone(nn.Module):
|
| 483 |
+
def __init__(self, config):
|
| 484 |
+
super().__init__()
|
| 485 |
+
self.config = config
|
| 486 |
+
self.embed_tokens = nn.Embedding(
|
| 487 |
+
config.vocab_size,
|
| 488 |
+
config.hidden_size,
|
| 489 |
+
padding_idx=config.pad_token_id if config.embedding_padding_idx else None,
|
| 490 |
+
)
|
| 491 |
+
self.relative_embedding = (
|
| 492 |
+
nn.Parameter(
|
| 493 |
+
torch.empty(
|
| 494 |
+
2 * config.position_buckets - 1, config.hidden_size
|
| 495 |
+
)
|
| 496 |
+
)
|
| 497 |
+
if config.shared_relative_embeddings
|
| 498 |
+
else None
|
| 499 |
+
)
|
| 500 |
+
self.relative_norm = (
|
| 501 |
+
nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
| 502 |
+
if config.shared_relative_embeddings
|
| 503 |
+
else None
|
| 504 |
+
)
|
| 505 |
+
if self.relative_embedding is not None:
|
| 506 |
+
nn.init.trunc_normal_(
|
| 507 |
+
self.relative_embedding,
|
| 508 |
+
std=config.initializer_range,
|
| 509 |
+
a=-2 * config.initializer_range,
|
| 510 |
+
b=2 * config.initializer_range,
|
| 511 |
+
)
|
| 512 |
+
self.geometry_lexical_dim = int(config.geometry_lexical_dim)
|
| 513 |
+
if not 0 <= self.geometry_lexical_dim < config.hidden_size:
|
| 514 |
+
raise ValueError("geometry_lexical_dim must be in [0, hidden_size)")
|
| 515 |
+
self.geometry_curvature = float(config.geometry_curvature)
|
| 516 |
+
if self.geometry_curvature <= 0:
|
| 517 |
+
raise ValueError("geometry_curvature must be positive")
|
| 518 |
+
self.lexical_angle = None
|
| 519 |
+
self.lexical_radius = None
|
| 520 |
+
if self.geometry_lexical_dim:
|
| 521 |
+
self.lexical_angle = nn.Embedding(
|
| 522 |
+
config.vocab_size, self.geometry_lexical_dim, config.pad_token_id
|
| 523 |
+
)
|
| 524 |
+
self.lexical_radius = nn.Embedding(config.vocab_size, 1, config.pad_token_id)
|
| 525 |
+
self.lexical_residual = (
|
| 526 |
+
LexicalResidualEmbedding(config)
|
| 527 |
+
if config.lexical_residual_buckets
|
| 528 |
+
else None
|
| 529 |
+
)
|
| 530 |
+
self.embed_positions = (
|
| 531 |
+
nn.Embedding(config.max_seq_len, config.hidden_size)
|
| 532 |
+
if getattr(config, "absolute_positions", False)
|
| 533 |
+
else None
|
| 534 |
+
)
|
| 535 |
+
self.embed_norm = nn.LayerNorm(
|
| 536 |
+
config.hidden_size,
|
| 537 |
+
eps=config.layer_norm_eps,
|
| 538 |
+
elementwise_affine=False,
|
| 539 |
+
)
|
| 540 |
+
self.dropout = nn.Dropout(config.dropout)
|
| 541 |
+
self.blocks = nn.ModuleList(
|
| 542 |
+
GPTBertBlock(config) for _ in range(config.num_hidden_layers)
|
| 543 |
+
)
|
| 544 |
+
self.recurrent_steps = max(1, int(config.recurrent_steps))
|
| 545 |
+
self.future_projections = nn.ModuleDict(
|
| 546 |
+
{
|
| 547 |
+
str(offset): nn.Linear(
|
| 548 |
+
config.hidden_size, config.hidden_size, bias=False
|
| 549 |
+
)
|
| 550 |
+
for offset in config.future_offsets
|
| 551 |
+
}
|
| 552 |
+
)
|
| 553 |
+
self.residual_mixer = (
|
| 554 |
+
DynamicWeightedAverage(config.num_hidden_layers * self.recurrent_steps * 2)
|
| 555 |
+
if config.residual_mixing
|
| 556 |
+
else None
|
| 557 |
+
)
|
| 558 |
+
self.cognitive_readout_layer = int(config.cognitive_readout_layer)
|
| 559 |
+
self.cognitive_readout_weight = float(config.cognitive_readout_weight)
|
| 560 |
+
maximum_depth = config.num_hidden_layers * self.recurrent_steps
|
| 561 |
+
if self.cognitive_readout_layer > maximum_depth:
|
| 562 |
+
raise ValueError("cognitive_readout_layer exceeds the executed depth")
|
| 563 |
+
|
| 564 |
+
def lexical_geometry(self, token_ids):
|
| 565 |
+
if self.lexical_angle is None or self.lexical_radius is None:
|
| 566 |
+
raise RuntimeError("lexical geometry is disabled")
|
| 567 |
+
direction = F.normalize(self.lexical_angle(token_ids), dim=-1)
|
| 568 |
+
radius = F.softplus(self.lexical_radius(token_ids)).squeeze(-1)
|
| 569 |
+
scale = math.sqrt(self.geometry_curvature)
|
| 570 |
+
point = torch.tanh(scale * radius / 2).unsqueeze(-1) * direction / scale
|
| 571 |
+
return point, radius
|
| 572 |
+
|
| 573 |
+
def forward(self, input_ids, mask):
|
| 574 |
+
embedded = self.embed_tokens(input_ids)
|
| 575 |
+
if self.lexical_residual is not None:
|
| 576 |
+
embedded = embedded + self.lexical_residual(input_ids)
|
| 577 |
+
if self.geometry_lexical_dim:
|
| 578 |
+
_, radius = self.lexical_geometry(input_ids)
|
| 579 |
+
direction = F.normalize(self.lexical_angle(input_ids), dim=-1)
|
| 580 |
+
tangent = radius.unsqueeze(-1) * direction
|
| 581 |
+
embedded = torch.cat((embedded[..., :-self.geometry_lexical_dim], tangent), -1)
|
| 582 |
+
if self.embed_positions is not None:
|
| 583 |
+
positions = torch.arange(input_ids.size(1), device=input_ids.device)
|
| 584 |
+
embedded = embedded + self.embed_positions(positions)
|
| 585 |
+
hidden = self.dropout(self.embed_norm(embedded))
|
| 586 |
+
mixer = self.residual_mixer
|
| 587 |
+
if mixer is not None:
|
| 588 |
+
mixer.initialize(hidden)
|
| 589 |
+
sublayer = 0
|
| 590 |
+
cognitive_hidden = None
|
| 591 |
+
layer_index = 0
|
| 592 |
+
relative = (
|
| 593 |
+
self.relative_norm(self.relative_embedding)
|
| 594 |
+
if self.relative_norm is not None and self.relative_embedding is not None
|
| 595 |
+
else None
|
| 596 |
+
)
|
| 597 |
+
for _ in range(self.recurrent_steps):
|
| 598 |
+
for block in self.blocks:
|
| 599 |
+
hidden = hidden + block.attend(hidden, mask, relative)
|
| 600 |
+
if mixer is not None:
|
| 601 |
+
hidden = mixer(hidden, sublayer)
|
| 602 |
+
sublayer += 1
|
| 603 |
+
hidden = hidden + block.transform(hidden)
|
| 604 |
+
if mixer is not None:
|
| 605 |
+
hidden = mixer(hidden, sublayer)
|
| 606 |
+
sublayer += 1
|
| 607 |
+
layer_index += 1
|
| 608 |
+
if layer_index == self.cognitive_readout_layer:
|
| 609 |
+
cognitive_hidden = hidden
|
| 610 |
+
if cognitive_hidden is not None and self.cognitive_readout_weight > 0:
|
| 611 |
+
weight = self.cognitive_readout_weight
|
| 612 |
+
hidden = (1.0 - weight) * hidden + weight * cognitive_hidden
|
| 613 |
+
return hidden
|
| 614 |
+
|
| 615 |
+
|
| 616 |
+
class DirectSumStream(nn.Module):
|
| 617 |
+
def __init__(self, config):
|
| 618 |
+
super().__init__()
|
| 619 |
+
self.relative_embedding = (
|
| 620 |
+
nn.Parameter(torch.empty(2 * config.position_buckets - 1, config.hidden_size))
|
| 621 |
+
if config.shared_relative_embeddings
|
| 622 |
+
else None
|
| 623 |
+
)
|
| 624 |
+
self.relative_norm = (
|
| 625 |
+
nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
|
| 626 |
+
if config.shared_relative_embeddings
|
| 627 |
+
else None
|
| 628 |
+
)
|
| 629 |
+
if self.relative_embedding is not None:
|
| 630 |
+
nn.init.trunc_normal_(
|
| 631 |
+
self.relative_embedding,
|
| 632 |
+
std=config.initializer_range,
|
| 633 |
+
a=-2 * config.initializer_range,
|
| 634 |
+
b=2 * config.initializer_range,
|
| 635 |
+
)
|
| 636 |
+
self.embed_positions = (
|
| 637 |
+
nn.Embedding(config.max_seq_len, config.hidden_size)
|
| 638 |
+
if config.absolute_positions
|
| 639 |
+
else None
|
| 640 |
+
)
|
| 641 |
+
self.embed_norm = nn.LayerNorm(
|
| 642 |
+
config.hidden_size,
|
| 643 |
+
eps=config.layer_norm_eps,
|
| 644 |
+
elementwise_affine=False,
|
| 645 |
+
)
|
| 646 |
+
self.dropout = nn.Dropout(config.dropout)
|
| 647 |
+
self.blocks = nn.ModuleList(
|
| 648 |
+
GPTBertBlock(config) for _ in range(config.num_hidden_layers)
|
| 649 |
+
)
|
| 650 |
+
self.recurrent_steps = max(1, int(config.recurrent_steps))
|
| 651 |
+
self.residual_mixer = (
|
| 652 |
+
DynamicWeightedAverage(config.num_hidden_layers * self.recurrent_steps * 2)
|
| 653 |
+
if config.residual_mixing
|
| 654 |
+
else None
|
| 655 |
+
)
|
| 656 |
+
|
| 657 |
+
def forward(self, embedded, mask):
|
| 658 |
+
if self.embed_positions is not None:
|
| 659 |
+
positions = torch.arange(embedded.size(1), device=embedded.device)
|
| 660 |
+
embedded = embedded + self.embed_positions(positions)
|
| 661 |
+
hidden = self.dropout(self.embed_norm(embedded))
|
| 662 |
+
mixer = self.residual_mixer
|
| 663 |
+
if mixer is not None:
|
| 664 |
+
mixer.initialize(hidden)
|
| 665 |
+
relative = (
|
| 666 |
+
self.relative_norm(self.relative_embedding)
|
| 667 |
+
if self.relative_norm is not None and self.relative_embedding is not None
|
| 668 |
+
else None
|
| 669 |
+
)
|
| 670 |
+
sublayer = 0
|
| 671 |
+
for _ in range(self.recurrent_steps):
|
| 672 |
+
for block in self.blocks:
|
| 673 |
+
hidden = hidden + block.attend(hidden, mask, relative)
|
| 674 |
+
if mixer is not None:
|
| 675 |
+
hidden = mixer(hidden, sublayer)
|
| 676 |
+
sublayer += 1
|
| 677 |
+
hidden = hidden + block.transform(hidden)
|
| 678 |
+
if mixer is not None:
|
| 679 |
+
hidden = mixer(hidden, sublayer)
|
| 680 |
+
sublayer += 1
|
| 681 |
+
return hidden
|
| 682 |
+
|
| 683 |
+
|
| 684 |
+
class DirectSumBackbone(nn.Module):
|
| 685 |
+
def __init__(self, config):
|
| 686 |
+
super().__init__()
|
| 687 |
+
dims = tuple(int(value) for value in config.direct_sum_dims)
|
| 688 |
+
heads = tuple(int(value) for value in config.direct_sum_heads)
|
| 689 |
+
widths = tuple(int(value) for value in config.direct_sum_intermediate_sizes)
|
| 690 |
+
if len(dims) != 3 or len(heads) != 3 or len(widths) != 3:
|
| 691 |
+
raise ValueError("direct sum requires three dims, heads and FFN widths")
|
| 692 |
+
if sum(dims) != config.hidden_size:
|
| 693 |
+
raise ValueError("direct_sum_dims must sum to hidden_size")
|
| 694 |
+
if any(dim % head for dim, head in zip(dims, heads)):
|
| 695 |
+
raise ValueError("each direct-sum dimension must divide its head count")
|
| 696 |
+
self.dims = dims
|
| 697 |
+
self.embed_tokens = nn.Embedding(
|
| 698 |
+
config.vocab_size,
|
| 699 |
+
config.hidden_size,
|
| 700 |
+
padding_idx=config.pad_token_id if config.embedding_padding_idx else None,
|
| 701 |
+
)
|
| 702 |
+
streams = []
|
| 703 |
+
for dim, head, width in zip(dims, heads, widths):
|
| 704 |
+
stream_config = copy.copy(config)
|
| 705 |
+
stream_config.hidden_size = dim
|
| 706 |
+
stream_config.num_attention_heads = head
|
| 707 |
+
stream_config.intermediate_size = width
|
| 708 |
+
stream_config.direct_sum_dims = []
|
| 709 |
+
stream_config.direct_sum_heads = []
|
| 710 |
+
stream_config.direct_sum_intermediate_sizes = []
|
| 711 |
+
stream_config.geometry_lexical_dim = 0
|
| 712 |
+
stream_config.future_offsets = []
|
| 713 |
+
stream_config.cognitive_readout_layer = 0
|
| 714 |
+
stream_config.cognitive_readout_weight = 0.0
|
| 715 |
+
streams.append(DirectSumStream(stream_config))
|
| 716 |
+
self.streams = nn.ModuleList(streams)
|
| 717 |
+
self.concept_radius = nn.Embedding(
|
| 718 |
+
config.vocab_size, 1, padding_idx=config.pad_token_id
|
| 719 |
+
)
|
| 720 |
+
|
| 721 |
+
@property
|
| 722 |
+
def factor_slices(self):
|
| 723 |
+
syntax, lexical, conceptual = self.dims
|
| 724 |
+
return (
|
| 725 |
+
slice(0, syntax),
|
| 726 |
+
slice(syntax, syntax + lexical),
|
| 727 |
+
slice(syntax + lexical, syntax + lexical + conceptual),
|
| 728 |
+
)
|
| 729 |
+
|
| 730 |
+
def conceptual_geometry(self, token_ids):
|
| 731 |
+
conceptual = self.embed_tokens(token_ids)[..., self.factor_slices[2]]
|
| 732 |
+
direction = F.normalize(conceptual, dim=-1)
|
| 733 |
+
radius = (1.0 - 1.0e-4) * torch.sigmoid(
|
| 734 |
+
self.concept_radius(token_ids).squeeze(-1)
|
| 735 |
+
)
|
| 736 |
+
if self.concept_radius.padding_idx is not None:
|
| 737 |
+
radius = radius.masked_fill(
|
| 738 |
+
token_ids.eq(self.concept_radius.padding_idx), 0.0
|
| 739 |
+
)
|
| 740 |
+
return radius.unsqueeze(-1) * direction, radius
|
| 741 |
+
|
| 742 |
+
def forward(self, input_ids, mask):
|
| 743 |
+
embedded = self.embed_tokens(input_ids)
|
| 744 |
+
conceptual, _ = self.conceptual_geometry(input_ids)
|
| 745 |
+
parts = list(embedded.split(self.dims, dim=-1))
|
| 746 |
+
parts[2] = conceptual
|
| 747 |
+
return torch.cat(
|
| 748 |
+
[stream(part, mask) for stream, part in zip(self.streams, parts)], dim=-1
|
| 749 |
+
)
|
| 750 |
+
|
| 751 |
+
|
| 752 |
+
def _backbone(config):
|
| 753 |
+
return DirectSumBackbone(config) if config.direct_sum_dims else GPTBertBackbone(config)
|
| 754 |
+
|
| 755 |
+
|
| 756 |
+
def _structured_projections(config):
|
| 757 |
+
width = int(config.structured_projection_dim)
|
| 758 |
+
return (
|
| 759 |
+
nn.ModuleDict(
|
| 760 |
+
{
|
| 761 |
+
"syntax": nn.Linear(config.hidden_size, width, bias=False),
|
| 762 |
+
"lexical": nn.Linear(config.hidden_size, width, bias=False),
|
| 763 |
+
}
|
| 764 |
+
)
|
| 765 |
+
if width
|
| 766 |
+
else nn.ModuleDict()
|
| 767 |
+
)
|
| 768 |
+
|
| 769 |
+
|
| 770 |
+
class GPTBertLMHead(nn.Module):
|
| 771 |
+
def __init__(self, config):
|
| 772 |
+
super().__init__()
|
| 773 |
+
self.norm = nn.LayerNorm(
|
| 774 |
+
config.hidden_size,
|
| 775 |
+
eps=config.layer_norm_eps,
|
| 776 |
+
elementwise_affine=False,
|
| 777 |
+
)
|
| 778 |
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
| 779 |
+
self.post_norm = nn.LayerNorm(
|
| 780 |
+
config.hidden_size,
|
| 781 |
+
eps=config.layer_norm_eps,
|
| 782 |
+
elementwise_affine=False,
|
| 783 |
+
)
|
| 784 |
+
self.dropout = nn.Dropout(config.dropout)
|
| 785 |
+
self._approximate = config.lm_head_gelu_approximate
|
| 786 |
+
self.bias = nn.Parameter(torch.zeros(config.vocab_size))
|
| 787 |
+
|
| 788 |
+
def forward(self, hidden):
|
| 789 |
+
projected = self.dropout(
|
| 790 |
+
self.post_norm(
|
| 791 |
+
F.gelu(
|
| 792 |
+
self.dense(self.norm(hidden)), approximate=self._approximate
|
| 793 |
+
)
|
| 794 |
+
)
|
| 795 |
+
)
|
| 796 |
+
return F.linear(projected, self.weight, self.bias)
|
| 797 |
+
|
| 798 |
+
|
| 799 |
+
class TOLMModel(PreTrainedModel):
|
| 800 |
+
config_class = TOLMConfig
|
| 801 |
+
base_model_prefix = "tolm"
|
| 802 |
+
_no_split_modules = ["GPTBertBlock"]
|
| 803 |
+
|
| 804 |
+
def __init__(self, config):
|
| 805 |
+
super().__init__(config)
|
| 806 |
+
self.backbone = _backbone(config)
|
| 807 |
+
self.structured_projections = _structured_projections(config)
|
| 808 |
+
self.post_init()
|
| 809 |
+
|
| 810 |
+
def get_input_embeddings(self):
|
| 811 |
+
return self.backbone.embed_tokens
|
| 812 |
+
|
| 813 |
+
def forward(self, input_ids=None, attention_mask=None, **kwargs):
|
| 814 |
+
if input_ids is None:
|
| 815 |
+
raise ValueError("input_ids is required")
|
| 816 |
+
hidden = self.backbone(
|
| 817 |
+
input_ids, _bidirectional_mask(_valid_tokens(input_ids, attention_mask))
|
| 818 |
+
)
|
| 819 |
+
return BaseModelOutput(
|
| 820 |
+
last_hidden_state=hidden, hidden_states=None, attentions=None
|
| 821 |
+
)
|
| 822 |
+
|
| 823 |
+
|
| 824 |
+
class TOLMForMaskedLM(PreTrainedModel):
|
| 825 |
+
config_class = TOLMConfig
|
| 826 |
+
base_model_prefix = "tolm"
|
| 827 |
+
_no_split_modules = ["GPTBertBlock"]
|
| 828 |
+
_tied_weights_keys = ["heads.lm.weight"]
|
| 829 |
+
|
| 830 |
+
def __init__(self, config):
|
| 831 |
+
super().__init__(config)
|
| 832 |
+
self.backbone = _backbone(config)
|
| 833 |
+
head = GPTBertLMHead(config)
|
| 834 |
+
self.heads = nn.ModuleDict({"lm": head})
|
| 835 |
+
self.structured_projections = _structured_projections(config)
|
| 836 |
+
if config.direct_sum_dims:
|
| 837 |
+
self.factor_dual_lambdas = nn.Parameter(
|
| 838 |
+
torch.ones(3), requires_grad=False
|
| 839 |
+
)
|
| 840 |
+
self.post_init()
|
| 841 |
+
|
| 842 |
+
def get_input_embeddings(self):
|
| 843 |
+
return self.backbone.embed_tokens
|
| 844 |
+
|
| 845 |
+
def get_output_embeddings(self):
|
| 846 |
+
return self.heads["lm"]
|
| 847 |
+
|
| 848 |
+
def forward(self, input_ids=None, attention_mask=None, labels=None, **kwargs):
|
| 849 |
+
if input_ids is None:
|
| 850 |
+
raise ValueError("input_ids is required")
|
| 851 |
+
hidden = self.backbone(
|
| 852 |
+
input_ids, _bidirectional_mask(_valid_tokens(input_ids, attention_mask))
|
| 853 |
+
)
|
| 854 |
+
logits = self.heads["lm"](hidden)
|
| 855 |
+
loss = (
|
| 856 |
+
None
|
| 857 |
+
if labels is None
|
| 858 |
+
else F.cross_entropy(
|
| 859 |
+
logits.view(-1, logits.size(-1)), labels.view(-1), ignore_index=-100
|
| 860 |
+
)
|
| 861 |
+
)
|
| 862 |
+
return MaskedLMOutput(
|
| 863 |
+
loss=loss, logits=logits, hidden_states=None, attentions=None
|
| 864 |
+
)
|
| 865 |
+
|
| 866 |
+
|
| 867 |
+
class TOLMForCausalLM(PreTrainedModel):
|
| 868 |
+
config_class = TOLMConfig
|
| 869 |
+
base_model_prefix = "tolm"
|
| 870 |
+
_no_split_modules = ["GPTBertBlock"]
|
| 871 |
+
_tied_weights_keys = ["heads.lm.weight"]
|
| 872 |
+
|
| 873 |
+
def __init__(self, config):
|
| 874 |
+
super().__init__(config)
|
| 875 |
+
self.backbone = _backbone(config)
|
| 876 |
+
head = GPTBertLMHead(config)
|
| 877 |
+
self.heads = nn.ModuleDict({"lm": head})
|
| 878 |
+
self.structured_projections = _structured_projections(config)
|
| 879 |
+
if config.direct_sum_dims:
|
| 880 |
+
self.factor_dual_lambdas = nn.Parameter(
|
| 881 |
+
torch.ones(3), requires_grad=False
|
| 882 |
+
)
|
| 883 |
+
self.post_init()
|
| 884 |
+
|
| 885 |
+
def get_input_embeddings(self):
|
| 886 |
+
return self.backbone.embed_tokens
|
| 887 |
+
|
| 888 |
+
def get_output_embeddings(self):
|
| 889 |
+
return self.heads["lm"]
|
| 890 |
+
|
| 891 |
+
def prepare_inputs_for_generation(self, input_ids, attention_mask=None, **kwargs):
|
| 892 |
+
return {"input_ids": input_ids, "attention_mask": attention_mask}
|
| 893 |
+
|
| 894 |
+
def forward(self, input_ids=None, attention_mask=None, labels=None, **kwargs):
|
| 895 |
+
if input_ids is None:
|
| 896 |
+
raise ValueError("input_ids is required")
|
| 897 |
+
hidden = self.backbone(
|
| 898 |
+
input_ids, _causal_mask(_valid_tokens(input_ids, attention_mask))
|
| 899 |
+
)
|
| 900 |
+
logits = self.heads["lm"](hidden)
|
| 901 |
+
loss = None
|
| 902 |
+
if labels is not None:
|
| 903 |
+
loss = F.cross_entropy(
|
| 904 |
+
logits[:, :-1].contiguous().view(-1, logits.size(-1)),
|
| 905 |
+
labels[:, 1:].contiguous().view(-1),
|
| 906 |
+
ignore_index=-100,
|
| 907 |
+
)
|
| 908 |
+
return CausalLMOutput(
|
| 909 |
+
loss=loss, logits=logits, hidden_states=None, attentions=None
|
| 910 |
+
)
|
training_manifest.json
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
|
|
|
|
|
|
|
|
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d",
|
| 5 |
+
"corpus_source_sha256": "25bd27eec0d21e0ec3e33a0467c91f9f3d1d6f78adc25369720cc0289e191bf3",
|
| 6 |
+
"corpus_tokens_sha256": "e5d4fc1f685dbec12ce458e257e4d9bfb39fc084cbbcedc5963229800ee8ac52",
|
| 7 |
+
"corpus_words": 8900000,
|
| 8 |
+
"corpus_words_sha256": "4036ddbe4921b35fb732d9cffb46f968c58ed8463def22bb846a35f5250790c3",
|
| 9 |
+
"document_order_sha256": null,
|
| 10 |
+
"factor_manifest_sha256": null,
|
| 11 |
+
"factorization_manifest_sha256": "52f31760faac4620008f19dbb6533b4b1856831f7e2b94fdb178b3b06803605a",
|
| 12 |
+
"influence_preflight_sha256": null,
|
| 13 |
+
"repositories": {
|
| 14 |
+
"encoded_corpus": {
|
| 15 |
+
"repo": "miguelcsx/babylm-bbpe16k-512-encoded",
|
| 16 |
+
"repo_type": "dataset",
|
| 17 |
+
"revision": "a62a6f274f3d86c05c8dd967a0c7200573ae9ef6"
|
| 18 |
+
},
|
| 19 |
+
"encoded_factorized_real": {
|
| 20 |
+
"repo": "miguelcsx/factorized-strict-small-real-corpus",
|
| 21 |
+
"repo_type": "dataset",
|
| 22 |
+
"revision": "b86f852224ea8f3c150f395209e447f5223c7aa0"
|
| 23 |
+
},
|
| 24 |
+
"factorization_priors": {
|
| 25 |
+
"repo": "miguelcsx/factorized-strict-small-priors",
|
| 26 |
+
"repo_type": "dataset",
|
| 27 |
+
"revision": "3ea2f0d08ce87f20ce8986a4a08374ca8cc4f23f"
|
| 28 |
+
},
|
| 29 |
+
"tokenizer": {
|
| 30 |
+
"repo": "miguelcsx/causal-focus-bbpe16k-tokenizer",
|
| 31 |
+
"repo_type": "model",
|
| 32 |
+
"revision": "5c95ae8fe9cc0f745f8d643192775fbceff5fedb"
|
| 33 |
+
},
|
| 34 |
+
"tokenizer_factorized": {
|
| 35 |
+
"repo": "miguelcsx/factorized-strict-small-bpe16k-tokenizer",
|
| 36 |
+
"repo_type": "model",
|
| 37 |
+
"revision": "a1f87b2b439ea988ba2b94b62898ed44780fb5e5"
|
| 38 |
+
}
|
| 39 |
+
},
|
| 40 |
+
"structured_priors_manifest_sha256": "ee75fe93d2dffd4bc7d86d1a1fd9f1aa1d76a956012dc6357274a252f40d8bbf",
|
| 41 |
+
"tokenizer_sha256": "2b8d1b3f51c0d8f276a64ea6a69efa50b4d9899780f1b282b4d0dcb7be5bbb0f",
|
| 42 |
+
"tokenizer_word_start_sha256": "42d9a905c49df4c54dbe3bc93e567c9bbe491ec6fbee5fcbed70e8d1ad533d49"
|
| 43 |
+
},
|
| 44 |
+
"compliance": {
|
| 45 |
+
"auxiliary_linguistic_training_words": 1000000,
|
| 46 |
+
"books_are_not_additive": true,
|
| 47 |
+
"brown_training_words": 1000000,
|
| 48 |
+
"competition_status": "strict_small_two_book_accounting",
|
| 49 |
+
"conservative_corpus_accounting_words": 10000000,
|
| 50 |
+
"corpus_book_words": 10000000,
|
| 51 |
+
"corpus_induced_priors": true,
|
| 52 |
+
"corpus_limit_words": 10000000,
|
| 53 |
+
"evaluation_holdout_words": 100000,
|
| 54 |
+
"exposure_limit_words": 100000000,
|
| 55 |
+
"external_teacher": false,
|
| 56 |
+
"generated_words": 0,
|
| 57 |
+
"induction_corpus_disjoint_from_lm_and_holdout": true,
|
| 58 |
+
"leaderboard_checkpoint_words": 100000000,
|
| 59 |
+
"model_exposure_book_words": 8000000,
|
| 60 |
+
"model_exposure_words": 8000000,
|
| 61 |
+
"model_training_corpus_words": 8900000,
|
| 62 |
+
"ppmi_induction_words": 1000000,
|
| 63 |
+
"relational_corpus_fraction": 0.025,
|
| 64 |
+
"same_run_checkpoint_distribution": false,
|
| 65 |
+
"signals_derived_from_current_model_input": false,
|
| 66 |
+
"strict_small_status": "within_independent_corpus_and_exposure_books",
|
| 67 |
+
"syntax_training_words": 0,
|
| 68 |
+
"teacher_queries": 0,
|
| 69 |
+
"tokenizer_training_words": 8900000,
|
| 70 |
+
"tool_training_uses_are_corpus_subsets": true,
|
| 71 |
+
"total_exposure_words": 100000000,
|
| 72 |
+
"track": "strict-small",
|
| 73 |
+
"unique_corpus_words": 10000000,
|
| 74 |
+
"within_track_corpus_budget": true,
|
| 75 |
+
"within_track_exposure_budget": true
|
| 76 |
+
},
|
| 77 |
+
"factor_priors": {
|
| 78 |
+
"angular_margin": 0.1,
|
| 79 |
+
"dual": {
|
| 80 |
+
"enabled": false,
|
| 81 |
+
"learning_rate": 0.001,
|
| 82 |
+
"max_weight": 1.0,
|
| 83 |
+
"targets": [
|
| 84 |
+
1.0,
|
| 85 |
+
4.0,
|
| 86 |
+
0.1
|
| 87 |
+
]
|
| 88 |
+
},
|
| 89 |
+
"enabled": false,
|
| 90 |
+
"lambda_conceptual": 0.0,
|
| 91 |
+
"lambda_lexical": 0.0,
|
| 92 |
+
"lambda_syntax": 0.0,
|
| 93 |
+
"max_positions": 256,
|
| 94 |
+
"radial_margin": 0.02,
|
| 95 |
+
"radial_weight": 1.0,
|
| 96 |
+
"randomize": false,
|
| 97 |
+
"randomize_seed": 42,
|
| 98 |
+
"syntax_depth_weight": 0.1,
|
| 99 |
+
"syntax_distance_weight": 0.1,
|
| 100 |
+
"syntax_window": 32,
|
| 101 |
+
"temperature": 0.07,
|
| 102 |
+
"warmup_words": 1000000
|
| 103 |
+
},
|
| 104 |
+
"factorization": {
|
| 105 |
+
"context_window": 4,
|
| 106 |
+
"covariance_weight": 0.005,
|
| 107 |
+
"cross_covariance_weight": 0.002,
|
| 108 |
+
"enabled": true,
|
| 109 |
+
"gradient_budget": 0.1,
|
| 110 |
+
"gradient_ema_momentum": 0.95,
|
| 111 |
+
"graph_mode": "real",
|
| 112 |
+
"loss_enabled": true,
|
| 113 |
+
"max_gradient_scale": 1000.0,
|
| 114 |
+
"null_seed": 271828,
|
| 115 |
+
"pairs_per_microbatch": 128,
|
| 116 |
+
"ramp_words": 5000000,
|
| 117 |
+
"regularizer_words": 512,
|
| 118 |
+
"signal_mode": "induced_priors",
|
| 119 |
+
"temperature": 0.07,
|
| 120 |
+
"variance_weight": 0.02
|
| 121 |
+
},
|
| 122 |
+
"geometry": {
|
| 123 |
+
"curvature": 1.0,
|
| 124 |
+
"distance_margin": 0.1,
|
| 125 |
+
"enabled": false,
|
| 126 |
+
"lambda_radial": 0.02,
|
| 127 |
+
"lambda_related": 0.02,
|
| 128 |
+
"max_tokens": 256,
|
| 129 |
+
"radial_margin": 0.05,
|
| 130 |
+
"warmup_words": 5000000
|
| 131 |
+
},
|
| 132 |
+
"model": {
|
| 133 |
+
"absolute_positions": false,
|
| 134 |
+
"attention_dropout": 0.1,
|
| 135 |
+
"bos_token_id": 1,
|
| 136 |
+
"cognitive_readout_layer": 0,
|
| 137 |
+
"cognitive_readout_weight": 0.0,
|
| 138 |
+
"direct_sum_dims": [],
|
| 139 |
+
"direct_sum_heads": [],
|
| 140 |
+
"direct_sum_intermediate_sizes": [],
|
| 141 |
+
"dropout": 0.1,
|
| 142 |
+
"eos_token_id": 2,
|
| 143 |
+
"expert_intermediate_size": null,
|
| 144 |
+
"experts_per_token": 1,
|
| 145 |
+
"factor_readout_dims": [
|
| 146 |
+
128,
|
| 147 |
+
128,
|
| 148 |
+
128
|
| 149 |
+
],
|
| 150 |
+
"factor_readout_mode": "oblique",
|
| 151 |
+
"factor_readout_reflectors": 384,
|
| 152 |
+
"factor_readout_seed": 314159,
|
| 153 |
+
"future_offsets": [],
|
| 154 |
+
"geometry_curvature": 1.0,
|
| 155 |
+
"geometry_lexical_dim": 0,
|
| 156 |
+
"hidden_size": 384,
|
| 157 |
+
"initializer_range": 0.03227486121839514,
|
| 158 |
+
"intermediate_size": 1280,
|
| 159 |
+
"lexical_residual_buckets": 0,
|
| 160 |
+
"lexical_residual_dim": 0,
|
| 161 |
+
"lexical_residual_scale": 1.0,
|
| 162 |
+
"mask_token_id": 4,
|
| 163 |
+
"max_seq_len": 512,
|
| 164 |
+
"num_attention_heads": 6,
|
| 165 |
+
"num_experts": 1,
|
| 166 |
+
"num_hidden_layers": 12,
|
| 167 |
+
"pad_token_id": 3,
|
| 168 |
+
"position_buckets": 32,
|
| 169 |
+
"recurrent_steps": 1,
|
| 170 |
+
"residual_mixing": true,
|
| 171 |
+
"rtd_auxiliary": true,
|
| 172 |
+
"state_mixer_kernel": 0,
|
| 173 |
+
"structured_projection_dim": 0,
|
| 174 |
+
"use_alibi": false,
|
| 175 |
+
"use_rope": false,
|
| 176 |
+
"value_gating": true,
|
| 177 |
+
"vocab_size": 16384
|
| 178 |
+
},
|
| 179 |
+
"release": "TOLM",
|
| 180 |
+
"repository": {
|
| 181 |
+
"commit": "ddca8805faf52c2c2d5ab1e4ca410ef2b6e0015f",
|
| 182 |
+
"tracked_dirty": false
|
| 183 |
+
},
|
| 184 |
+
"structured_priors": {
|
| 185 |
+
"decay_end_words": 7000000,
|
| 186 |
+
"enabled": false,
|
| 187 |
+
"hold_until_words": 2000000,
|
| 188 |
+
"init_scale": 0.0,
|
| 189 |
+
"lambda_lexical": 0.0,
|
| 190 |
+
"lambda_orth": 0.0,
|
| 191 |
+
"lambda_syntax": 0.0,
|
| 192 |
+
"lexical_dim": 128,
|
| 193 |
+
"max_positions": 256,
|
| 194 |
+
"prior_mode": "contrastive",
|
| 195 |
+
"randomize": false,
|
| 196 |
+
"representation": "slices",
|
| 197 |
+
"require_aligned_artifacts": false,
|
| 198 |
+
"syntax_dim": 128,
|
| 199 |
+
"temperature": 0.07,
|
| 200 |
+
"warmup_words": 100000
|
| 201 |
+
},
|
| 202 |
+
"training": {
|
| 203 |
+
"adaptive_masking": {
|
| 204 |
+
"enabled": false,
|
| 205 |
+
"max_mask_prob": 4.0,
|
| 206 |
+
"min_mask_prob": 0.25,
|
| 207 |
+
"momentum": 0.99
|
| 208 |
+
},
|
| 209 |
+
"batch_size": 16,
|
| 210 |
+
"beta1": 0.9,
|
| 211 |
+
"beta2": 0.98,
|
| 212 |
+
"causal_fraction": 0.0,
|
| 213 |
+
"causal_noise_kind": "random",
|
| 214 |
+
"causal_noise_probability": 0.0,
|
| 215 |
+
"causal_unit": "segment",
|
| 216 |
+
"cooldown_fraction": 0.016,
|
| 217 |
+
"data2vec_layers": 4,
|
| 218 |
+
"data2vec_weight": 0.0,
|
| 219 |
+
"device": "xpu:1",
|
| 220 |
+
"document_curriculum": {
|
| 221 |
+
"enabled": false
|
| 222 |
+
},
|
| 223 |
+
"ema_decay": 0.9998,
|
| 224 |
+
"epsilon": 1e-08,
|
| 225 |
+
"exact_word_checkpoints": true,
|
| 226 |
+
"exposure_words": 100000000,
|
| 227 |
+
"final_lr_ratio": 0.1,
|
| 228 |
+
"frequency_aware_masking": {
|
| 229 |
+
"enabled": false,
|
| 230 |
+
"max_mask_prob": 4.0,
|
| 231 |
+
"min_mask_prob": 0.25,
|
| 232 |
+
"temperature": 1.0
|
| 233 |
+
},
|
| 234 |
+
"future_loss_weight": 0.0,
|
| 235 |
+
"gradient_clip": 2.0,
|
| 236 |
+
"label_smoothing": 0.0,
|
| 237 |
+
"learning_progress": {
|
| 238 |
+
"buckets_per_axis": 4,
|
| 239 |
+
"enabled": false,
|
| 240 |
+
"fast_momentum": 0.9,
|
| 241 |
+
"forgetting_weight": 1.0,
|
| 242 |
+
"slow_momentum": 0.99,
|
| 243 |
+
"uniform_floor": 0.3,
|
| 244 |
+
"window_documents": 4000
|
| 245 |
+
},
|
| 246 |
+
"learning_rate": 0.0035,
|
| 247 |
+
"learning_rate_schedule": "cosine",
|
| 248 |
+
"log_interval": 50,
|
| 249 |
+
"mask_probability_end": 0.5,
|
| 250 |
+
"mask_probability_schedule": "uniform",
|
| 251 |
+
"mask_probability_start": 0.15,
|
| 252 |
+
"mask_replace_probability": 0.8,
|
| 253 |
+
"mask_schedule": "complementary",
|
| 254 |
+
"masked_fraction": 1.0,
|
| 255 |
+
"masking_unit": "word",
|
| 256 |
+
"microbatch_tokens": 8192,
|
| 257 |
+
"mixed_precision": "bf16",
|
| 258 |
+
"num_workers": 0,
|
| 259 |
+
"objective_period": 16,
|
| 260 |
+
"objective_rng_reset_words": [],
|
| 261 |
+
"objective_sanity_window_steps": 512,
|
| 262 |
+
"objective_schedule": "coverage",
|
| 263 |
+
"optimizer": "lamb",
|
| 264 |
+
"packing_strategy": "dense",
|
| 265 |
+
"pin_memory": false,
|
| 266 |
+
"random_replace_probability": 0.1,
|
| 267 |
+
"recombine_probability": 0.0,
|
| 268 |
+
"recombine_strategy": "random",
|
| 269 |
+
"recovery_interval_words": 1000000,
|
| 270 |
+
"resource_memory": {
|
| 271 |
+
"enabled": false
|
| 272 |
+
},
|
| 273 |
+
"router_aux_weight": 0.0,
|
| 274 |
+
"save_steps_words": [
|
| 275 |
+
1000000,
|
| 276 |
+
2000000,
|
| 277 |
+
3000000,
|
| 278 |
+
4000000,
|
| 279 |
+
5000000,
|
| 280 |
+
6000000,
|
| 281 |
+
7000000,
|
| 282 |
+
8000000,
|
| 283 |
+
9000000,
|
| 284 |
+
10000000,
|
| 285 |
+
20000000,
|
| 286 |
+
30000000,
|
| 287 |
+
40000000,
|
| 288 |
+
50000000,
|
| 289 |
+
60000000,
|
| 290 |
+
70000000,
|
| 291 |
+
80000000,
|
| 292 |
+
90000000,
|
| 293 |
+
100000000
|
| 294 |
+
],
|
| 295 |
+
"schedule_total_words": 100000000,
|
| 296 |
+
"span_max_length": 3,
|
| 297 |
+
"stable_fraction": 0.9,
|
| 298 |
+
"telemetry": {
|
| 299 |
+
"enabled": true,
|
| 300 |
+
"gradient_checkpoints_words": [
|
| 301 |
+
1000000,
|
| 302 |
+
10000000,
|
| 303 |
+
40000000,
|
| 304 |
+
70000000,
|
| 305 |
+
100000000
|
| 306 |
+
],
|
| 307 |
+
"sampler_trace": true
|
| 308 |
+
},
|
| 309 |
+
"threads_per_process": 10,
|
| 310 |
+
"tokens_per_update": 16384,
|
| 311 |
+
"warmup_fraction": 0.016,
|
| 312 |
+
"weight_decay": 0.1,
|
| 313 |
+
"z_loss_weight": 0.0001
|
| 314 |
+
},
|
| 315 |
+
"variant": "factorized_oblique",
|
| 316 |
+
"words_seen": 8000000
|
| 317 |
+
}
|