veriga commited on
Commit
6b13e5d
·
verified ·
1 Parent(s): 5300bf3

Update README with Parquet format docs

Browse files
Files changed (1) hide show
  1. README.md +66 -32
README.md CHANGED
@@ -18,30 +18,38 @@ size_categories:
18
 
19
  Precomputed hidden state activations before layer 23 of [Gemma-3-1B-IT](https://huggingface.co/google/gemma-3-1b-it) for the [OpenWebText](https://huggingface.co/datasets/Skylion007/openwebtext) dataset, tokenized with sequence length 1024.
20
 
21
- Designed for training a **[Titans](https://arxiv.org/abs/2501.00663)** memory layer replaced layer 23 of Gemma 3.
22
 
23
  ## Dataset Structure
24
 
25
- Each shard contains pre-computed forward pass outputs up to layer 23:
26
 
27
- | File | Shape | Dtype | Description |
28
- |------|-------|-------|-------------|
29
- | `shard_NNNNNN.npy` | `(64, 1024, 3072)` | `bfloat16` | Hidden state activations |
30
- | `shard_NNNNNN_masks.npy` | `(64, 1024)` | `int32` | Attention masks (1=real, 0=pad) |
31
- | `shard_NNNNNN_tokens.npy` | `(64, 1024)` | `int32` | Token IDs |
32
 
33
- - **Shards:** 1121 (000000–001120)
34
- - **Examples per shard:** 64
35
  - **Total examples:** ~71,744
 
 
36
  - **Sequence length:** 1024
37
- - **Hidden dimension:** 3072 (Gemma-3-1B embed_dim)
38
  - **Source model:** `google/gemma-3-1b-it`
39
  - **Source dataset:** `veriga/openwebtext-gemma3-tokenized-1024`
40
- - **Total size:** ~153 GB
 
 
 
 
 
 
 
 
41
 
42
  ## How It Was Created
43
 
44
- Activations were computed using a truncated forward pass through the first 23 Gemma 3 transformer layers. The process:
45
 
46
  1. Load OpenWebText tokens from `veriga/openwebtext-gemma3-tokenized-1024`
47
  2. Pad/truncate to 1024 tokens, generate attention masks
@@ -51,24 +59,28 @@ Activations were computed using a truncated forward pass through the first 23 Ge
51
 
52
  See the [precomputation notebook](https://github.com/andrew-veriga/Titans_jax/blob/main/colabs/Precompute_Activations_Gemma3_GPU.ipynb) for full details.
53
 
 
 
54
  ## Loading the Dataset
55
 
 
 
56
  ```python
57
  from datasets import load_dataset
58
 
59
  ds = load_dataset("veriga/openwebtext-gemma3-tokenized-1024-activations-layer23", split="train")
60
- ```
61
 
62
- Each example contains:
63
- ```python
64
- {
65
- "activations": np.ndarray, # shape (1024, 3072), float32 (cast from bfloat16)
66
- "mask": np.ndarray, # shape (1024,), int32
67
- "tokens": np.ndarray, # shape (1024,), int32
68
- }
 
69
  ```
70
 
71
- ### Streaming (recommended for large datasets)
72
 
73
  ```python
74
  ds = load_dataset(
@@ -77,30 +89,52 @@ ds = load_dataset(
77
  streaming=True
78
  )
79
 
 
80
  for example in ds:
81
- activations = example["activations"] # (1024, 3072)
82
- mask = example["mask"] # (1024,)
83
- tokens = example["tokens"] # (1024,)
84
  # Use for Titans training...
85
  ```
86
 
87
- ### Manual loading (without HF datasets)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  ```python
 
90
  import numpy as np
91
 
92
- shard_idx = 0
93
- activations = np.load(f"shard_{shard_idx:06d}.npy") # (64, 1024, 3072), bfloat16
94
- mask = np.load(f"shard_{shard_idx:06d}_masks.npy") # (64, 1024), int32
95
- tokens = np.load(f"shard_{shard_idx:06d}_tokens.npy") # (64, 1024), int32
96
  ```
97
 
98
  ## Use Case: Titans Memory Layer
99
 
100
- This dataset is intended for training a [Titans](https://arxiv.org/abs/2501.00663) long-term memory module to be inserted instead of layer 23 of Gemma 3. The precomputed activations allow training the memory layer independently without running the full model forward pass.
101
 
102
  ## Notes
103
 
104
- - Activations are stored in `bfloat16`; the HF Datasets loader casts them to `float32` for compatibility
105
  - Padding positions in activations are zeroed out via attention mask multiplication
106
- - The `metadata.json` file contains `{"next_shard": 1120}` used for resume during precomputation
 
18
 
19
  Precomputed hidden state activations before layer 23 of [Gemma-3-1B-IT](https://huggingface.co/google/gemma-3-1b-it) for the [OpenWebText](https://huggingface.co/datasets/Skylion007/openwebtext) dataset, tokenized with sequence length 1024.
20
 
21
+ Designed for training a **[Titans](https://arxiv.org/abs/2501.00663)** memory layer that replaces layer 23 of Gemma 3.
22
 
23
  ## Dataset Structure
24
 
25
+ Each example contains the inputs to layer 23:
26
 
27
+ | Field | Shape | Dtype | Description |
28
+ |-------|-------|-------|-------------|
29
+ | `activations` | `(1024, 1152)` | `float32` | Hidden state activations (cast from bfloat16) |
30
+ | `mask` | `(1024,)` | `int32` | Attention mask (1=real token, 0=pad) |
31
+ | `tokens` | `(1024,)` | `int32` | Token IDs |
32
 
 
 
33
  - **Total examples:** ~71,744
34
+ - **Examples per NPY shard:** 64
35
+ - **Examples per Parquet file:** 640 (10 NPY shards)
36
  - **Sequence length:** 1024
37
+ - **Hidden dimension:** 1152 (Gemma-3-1B embed_dim)
38
  - **Source model:** `google/gemma-3-1b-it`
39
  - **Source dataset:** `veriga/openwebtext-gemma3-tokenized-1024`
40
+
41
+ ### Files
42
+
43
+ | Format | Files | Location |
44
+ |--------|-------|----------|
45
+ | Parquet (recommended) | 113 files | `data/train-NNNNNN-NNNNNN.parquet` |
46
+ | NPY (original) | 3363 files | `shard_NNNNNN.npy`, `shard_NNNNNN_masks.npy`, `shard_NNNNNN_tokens.npy` |
47
+
48
+ Parquet files use **ZSTD compression** (level 3) and store activations as a flat `fixed_size_list<float32>[1179648]` (reshape to `1024 × 1152` after loading).
49
 
50
  ## How It Was Created
51
 
52
+ Activations were computed using a truncated forward pass through the first 23 Gemma 3 transformer layers:
53
 
54
  1. Load OpenWebText tokens from `veriga/openwebtext-gemma3-tokenized-1024`
55
  2. Pad/truncate to 1024 tokens, generate attention masks
 
59
 
60
  See the [precomputation notebook](https://github.com/andrew-veriga/Titans_jax/blob/main/colabs/Precompute_Activations_Gemma3_GPU.ipynb) for full details.
61
 
62
+ Parquet conversion: [Convert_NPY_to_Parquet.ipynb](https://github.com/andrew-veriga/Titans_jax/blob/main/colabs/Convert_NPY_to_Parquet.ipynb)
63
+
64
  ## Loading the Dataset
65
 
66
+ ### Standard (loads Parquet)
67
+
68
  ```python
69
  from datasets import load_dataset
70
 
71
  ds = load_dataset("veriga/openwebtext-gemma3-tokenized-1024-activations-layer23", split="train")
 
72
 
73
+ example = ds[0]
74
+ activations = example["activations"] # list of 1179648 floats
75
+ mask = example["mask"] # list of 1024 ints
76
+ tokens = example["tokens"] # list of 1024 ints
77
+
78
+ # Reshape activations
79
+ import numpy as np
80
+ act = np.array(activations, dtype=np.float32).reshape(1024, 1152)
81
  ```
82
 
83
+ ### Streaming (recommended no download)
84
 
85
  ```python
86
  ds = load_dataset(
 
89
  streaming=True
90
  )
91
 
92
+ import numpy as np
93
  for example in ds:
94
+ act = np.array(example["activations"], dtype=np.float32).reshape(1024, 1152)
95
+ mask = np.array(example["mask"])
96
+ tokens = np.array(example["tokens"])
97
  # Use for Titans training...
98
  ```
99
 
100
+ ### Direct Parquet access (no HF datasets)
101
+
102
+ ```python
103
+ import pyarrow.parquet as pq
104
+ import numpy as np
105
+
106
+ # From HuggingFace Hub
107
+ from huggingface_hub import hf_hub_download
108
+ path = hf_hub_download(
109
+ repo_id="veriga/openwebtext-gemma3-tokenized-1024-activations-layer23",
110
+ filename="data/train-000000-000009.parquet",
111
+ repo_type="dataset",
112
+ )
113
+
114
+ table = pq.read_table(path)
115
+ row = table.slice(0, 1).to_pydict()
116
+ act = np.array(row["activations"][0], dtype=np.float32).reshape(1024, 1152)
117
+ mask = np.array(row["mask"][0])
118
+ tokens = np.array(row["tokens"][0])
119
+ ```
120
+
121
+ ### Original NPY files
122
 
123
  ```python
124
+ import jax.numpy as jnp # or use ml_dtypes for np.load with bfloat16
125
  import numpy as np
126
 
127
+ activations = np.array(jnp.load("shard_000000.npy"), dtype=np.float32) # (64, 1024, 1152)
128
+ mask = np.load("shard_000000_masks.npy") # (64, 1024)
129
+ tokens = np.load("shard_000000_tokens.npy") # (64, 1024)
 
130
  ```
131
 
132
  ## Use Case: Titans Memory Layer
133
 
134
+ This dataset provides inputs for training a [Titans](https://arxiv.org/abs/2501.00663) long-term memory module that replaces layer 23 of Gemma 3. The precomputed activations allow training the memory layer independently without running the full model forward pass through the first 22 layers.
135
 
136
  ## Notes
137
 
138
+ - Original activations stored in `bfloat16` (NPY); Parquet cast to `float32`
139
  - Padding positions in activations are zeroed out via attention mask multiplication
140
+ - The first token in each sequence is the BOS token (ID=2)