1mage commited on
Commit
3752dc8
·
verified ·
1 Parent(s): 3d52925

Add dataset metadata and shard tools

Browse files
.gitattributes CHANGED
@@ -58,3 +58,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
58
  # Video files - compressed
59
  *.mp4 filter=lfs diff=lfs merge=lfs -text
60
  *.webm filter=lfs diff=lfs merge=lfs -text
61
+ manifest/three_stage.jsonl filter=lfs diff=lfs merge=lfs -text
62
+ manifest/two_stage.jsonl filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 SEELE-AI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
README.md ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pretty_name: Pixal3D Mesh and Prompt Dataset
4
+ tags:
5
+ - 3d-generation
6
+ - 3d-editing
7
+ - glb
8
+ ---
9
+
10
+ # Pixal3D Mesh and Prompt Dataset
11
+
12
+ This release contains the mesh and prompt records used for the Pixal3D editing data. The recommended Hugging Face distribution uses uncompressed TAR shards so that complete edit groups can be streamed without creating hundreds of thousands of independent repository objects.
13
+
14
+ ## Scope
15
+
16
+ The public release contains only:
17
+
18
+ - GLB mesh files for the complete three-stage edit chains.
19
+ - The base caption and edit instruction associated with each stage.
20
+ - Relative paths and SHA-256 checksums for integrity verification.
21
+
22
+ Point clouds, latent tensors, latent metadata, optimizer state, trainer state, and other training artifacts are excluded from this release.
23
+
24
+ ## Dataset structure
25
+
26
+ Each complete group contains the following ordered stages:
27
+
28
+ 1. `image0_base`: the base mesh and its base caption.
29
+ 2. `image1_edit1`: the first edited mesh and the instruction applied to the base stage.
30
+ 3. `image2_edit2`: the second edited mesh and the instruction applied to the first edited stage.
31
+
32
+ The package provides two manifest views:
33
+
34
+ - `manifest/three_stage.jsonl` contains one record per complete group and preserves the full three-stage chain.
35
+ - `manifest/two_stage.jsonl` contains one record per adjacent edit transition. Each group contributes a base-to-first-edit pair and a first-edit-to-second-edit pair.
36
+
37
+ The release contains 119,905 complete groups, 359,715 stage records, and 239,810 adjacent edit pairs.
38
+
39
+ The relative mesh layout inside each shard is:
40
+
41
+ ```text
42
+ meshes/<group_key>/<stage>/<filename>.glb
43
+ ```
44
+
45
+ ## Hugging Face distribution format
46
+
47
+ The upload package should use the following layout:
48
+
49
+ ```text
50
+ README.md
51
+ LICENSE
52
+ manifest/three_stage.jsonl
53
+ manifest/two_stage.jsonl
54
+ manifest/three_stage_sharded.jsonl
55
+ manifest/shard_index.jsonl
56
+ shards/shard-000000.tar
57
+ shards/shard-000001.tar
58
+ ...
59
+ ```
60
+
61
+ Each shard is an uncompressed TAR archive with a target size of approximately 2 GiB. A complete three-stage group is kept in one shard; a group is never split across shards. The TAR member names are the same relative mesh paths shown above. `manifest/shard_index.jsonl` maps each group and member to its shard, while `manifest/three_stage_sharded.jsonl` adds the shard reference to every mesh record. The uncompressed format avoids wasting CPU on already-compressed GLB buffers and supports standard TAR streaming and partial downloads.
62
+
63
+ The shard packer accepts a mounted source tree and writes one shard at a time, so the full dataset does not need to fit on local disk.
64
+
65
+ A three-stage manifest record has the following shape:
66
+
67
+ ```json
68
+ {
69
+ "schema_version": "pixal-open-source-record-v3",
70
+ "release_version": "pixal3d-mesh-prompt-20261102",
71
+ "group_key": "group_...",
72
+ "stage_chain": ["image0_base", "image1_edit1", "image2_edit2"],
73
+ "stages": [
74
+ {
75
+ "stage": "image0_base",
76
+ "mesh": {
77
+ "path": "meshes/group_.../image0_base/mesh_....glb",
78
+ "filename": "mesh_....glb",
79
+ "sha256": "..."
80
+ },
81
+ "prompt": {
82
+ "text": "...",
83
+ "kind": "base_caption",
84
+ "sha256": "...",
85
+ "parent_stage": null
86
+ }
87
+ }
88
+ ]
89
+ }
90
+ ```
91
+
92
+ ## Packing upload shards
93
+
94
+ For the full release, pack the sanitized three-stage manifest into approximately 2 GiB TAR shards:
95
+
96
+ ```bash
97
+ python tools/pack_shards_from_bos.py \
98
+ --manifest manifest/three_stage.jsonl \
99
+ --source-root /path/to/source/meshes \
100
+ --output-root .
101
+ ```
102
+
103
+ The packer verifies every source GLB against its manifest checksum while writing the TAR member. It writes `shards/`, `manifest/three_stage_sharded.jsonl`, and `manifest/shard_index.jsonl`. Use `--max-groups N` for a bounded smoke test. A production run can be executed on a host with enough temporary space for one shard and uploaded shard by shard to the Hugging Face repository.
104
+
105
+ ## Materializing mesh files
106
+
107
+ The manifests are metadata-only until the GLB files are materialized into the `meshes/` tree. The release tool can read from a mounted source dataset and copy one group or a bounded batch:
108
+
109
+ ```bash
110
+ python tools/materialize_from_bos.py \
111
+ --manifest manifest/three_stage.jsonl \
112
+ --source-root /path/to/source/meshes \
113
+ --output-root . \
114
+ --group-key group_...
115
+ ```
116
+
117
+ Use `--max-groups N` for a bounded batch. Use `--verify-only` to check source availability and SHA-256 values without writing files. The source root is intentionally supplied by the user and is not embedded in the public manifest.
118
+
119
+ ## Verification
120
+
121
+ The manifest records the SHA-256 value of every expected GLB. After materialization, verify a file with:
122
+
123
+ ```bash
124
+ sha256sum meshes/<group_key>/<stage>/<filename>.glb
125
+ ```
126
+
127
+ The expected values are in the corresponding `mesh.sha256` field. `manifest/sha256sums.txt` verifies the release metadata files themselves.
128
+
129
+ ## Attribution and limitations
130
+
131
+ The meshes are released as the Pixal3D mesh and prompt data associated with EVA01. The prompts describe the base object and the sequential edit instructions; they are not human-authored annotations for every geometric property. The GLB files may contain vertex colors and material information supported by the source generation pipeline. Consumers should validate rendering and downstream licensing requirements for their intended use.
132
+
133
+ This release does not include the EVA01 model weights or the TRELLIS.2 VAE/decoder weights. Those assets are distributed separately by their respective model repositories.
134
+
135
+ ## License
136
+
137
+ This dataset is released under the Apache License 2.0. See [LICENSE](LICENSE). The license applies to the released dataset materials; users remain responsible for checking any rights or restrictions associated with downstream assets and intended use.
manifest/sha256sums.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ 9b0405705760b4784e8aa3dc986f911cea9669a1a213820961156ab981a134d0 manifest/three_stage.jsonl
2
+ 15112eae8b0039ccb7ffa08ac4b34b47cbf29680e9242a82044ed6482413992b manifest/two_stage.jsonl
3
+ 3af4709b50e8ddf694168605d6c6893ad380867fb12ac1e19ae084382043675f metadata/release_receipt.json
manifest/three_stage.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b0405705760b4784e8aa3dc986f911cea9669a1a213820961156ab981a134d0
3
+ size 297522843
manifest/two_stage.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:15112eae8b0039ccb7ffa08ac4b34b47cbf29680e9242a82044ed6482413992b
3
+ size 445960578
metadata/release_receipt.json ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "schema_version": "pixal-open-source-release-receipt-v1",
3
+ "release_version": "pixal3d-mesh-prompt-20261102",
4
+ "created_at": "2026-11-02T00:00:00Z",
5
+ "scope": [
6
+ "mesh",
7
+ "prompt"
8
+ ],
9
+ "excluded_assets": [
10
+ "point_cloud",
11
+ "latent",
12
+ "safetensors",
13
+ "training_artifacts"
14
+ ],
15
+ "three_stage": {
16
+ "groups": 119905,
17
+ "records": 119905,
18
+ "stages_per_group": 3
19
+ },
20
+ "two_stage": {
21
+ "groups": 119905,
22
+ "records": 239810,
23
+ "pairs_per_group": 2
24
+ },
25
+ "stage_chain": [
26
+ "image0_base",
27
+ "image1_edit1",
28
+ "image2_edit2"
29
+ ],
30
+ "materialization": {
31
+ "status": "pending",
32
+ "mesh_files": 359715,
33
+ "source_validation": "manifest checksums are inherited from the verified source release; full local materialization is pending"
34
+ },
35
+ "validation": {
36
+ "prompt_nonempty": true,
37
+ "internal_paths_removed": true,
38
+ "internal_fields_removed": true,
39
+ "full_glb_hash_validation": "pending",
40
+ "prompt_sha256_verified": true,
41
+ "manifest_structure_verified": true
42
+ },
43
+ "license": "Apache-2.0",
44
+ "smoke_validation": {
45
+ "groups": 1,
46
+ "mesh_files": 3,
47
+ "sha256_matches": true,
48
+ "glb_header_validation": true
49
+ },
50
+ "distribution": {
51
+ "format": "uncompressed_tar_shards",
52
+ "target_shard_size_bytes": 2147483648,
53
+ "group_atomicity": "a complete three-stage group stays in one shard",
54
+ "mesh_member_layout": "meshes/<group_key>/<stage>/<filename>.glb",
55
+ "status": "planned",
56
+ "packer": "tools/pack_shards_from_bos.py"
57
+ },
58
+ "shard_smoke_validation": {
59
+ "groups": 1,
60
+ "mesh_files": 3,
61
+ "shards": 1,
62
+ "checksum_matches": true,
63
+ "tar_member_validation": true
64
+ }
65
+ }
tools/materialize_from_bos.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Materialize selected GLB files from a mounted source tree."""
3
+ from __future__ import annotations
4
+ import argparse
5
+ import hashlib
6
+ import json
7
+ import os
8
+ import shutil
9
+ from pathlib import Path
10
+ from typing import Any, Iterator
11
+
12
+ def sha256_file(path: Path) -> str:
13
+ digest = hashlib.sha256()
14
+ with path.open('rb') as handle:
15
+ for chunk in iter(lambda: handle.read(1024 * 1024), b''):
16
+ digest.update(chunk)
17
+ return digest.hexdigest()
18
+
19
+ def iter_records(manifest: Path) -> Iterator[dict[str, Any]]:
20
+ with manifest.open('r', encoding='utf-8') as handle:
21
+ for line_no, line in enumerate(handle, 1):
22
+ if not line.strip():
23
+ continue
24
+ try:
25
+ record = json.loads(line)
26
+ except json.JSONDecodeError as exc:
27
+ raise RuntimeError(f'{manifest}:{line_no}: invalid JSON: {exc}') from exc
28
+ yield record
29
+
30
+ def resolve_source(source_root: Path, relative_path: str) -> Path:
31
+ relative = Path(relative_path)
32
+ if relative.is_absolute() or '..' in relative.parts:
33
+ raise RuntimeError(f'unsafe manifest path: {relative_path}')
34
+ candidates = [source_root / relative]
35
+ if relative.parts and relative.parts[0] == 'meshes':
36
+ candidates.append(source_root / Path(*relative.parts[1:]))
37
+ for candidate in candidates:
38
+ if candidate.is_file():
39
+ return candidate
40
+ raise FileNotFoundError(f'source mesh not found for {relative_path}')
41
+
42
+ def materialize_record(record: dict[str, Any], source_root: Path, output_root: Path, verify_only: bool) -> tuple[int, int]:
43
+ group_key = record.get('group_key')
44
+ stages = record.get('stages')
45
+ if not isinstance(group_key, str) or not isinstance(stages, list):
46
+ raise RuntimeError('manifest record is missing group_key or stages')
47
+ copied = 0
48
+ for stage in stages:
49
+ mesh = stage.get('mesh') if isinstance(stage, dict) else None
50
+ if not isinstance(mesh, dict):
51
+ raise RuntimeError(f'missing mesh metadata for {group_key}')
52
+ relative_path = mesh.get('path')
53
+ expected = mesh.get('sha256')
54
+ if not isinstance(relative_path, str) or not isinstance(expected, str):
55
+ raise RuntimeError(f'invalid mesh metadata for {group_key}')
56
+ source = resolve_source(source_root, relative_path)
57
+ actual = sha256_file(source)
58
+ if actual != expected:
59
+ raise RuntimeError(f'checksum mismatch for {relative_path}: expected {expected}, got {actual}')
60
+ if not verify_only:
61
+ destination = output_root / relative_path
62
+ destination.parent.mkdir(parents=True, exist_ok=True)
63
+ temporary = destination.with_name(destination.name + '.partial')
64
+ with source.open('rb') as src, temporary.open('wb') as dst:
65
+ shutil.copyfileobj(src, dst, length=1024 * 1024)
66
+ os.replace(temporary, destination)
67
+ copied += 1
68
+ return 1, copied
69
+
70
+ def main() -> None:
71
+ parser = argparse.ArgumentParser(description=__doc__)
72
+ parser.add_argument('--manifest', type=Path, required=True, help='Sanitized three-stage JSONL manifest')
73
+ parser.add_argument('--source-root', type=Path, required=True, help='Mounted source mesh root or its parent dataset root')
74
+ parser.add_argument('--output-root', type=Path, default=Path('.'), help='Output dataset root')
75
+ parser.add_argument('--group-key', action='append', help='Materialize only this group; may be repeated')
76
+ parser.add_argument('--max-groups', type=int, help='Stop after this many selected groups')
77
+ parser.add_argument('--verify-only', action='store_true', help='Verify source existence and checksums without copying')
78
+ args = parser.parse_args()
79
+ if args.max_groups is not None and args.max_groups < 1:
80
+ parser.error('--max-groups must be positive')
81
+ selected = set(args.group_key or [])
82
+ groups, meshes = 0, 0
83
+ for record in iter_records(args.manifest):
84
+ group_key = record.get('group_key')
85
+ if selected and group_key not in selected:
86
+ continue
87
+ if args.max_groups is not None and groups >= args.max_groups:
88
+ break
89
+ group_count, mesh_count = materialize_record(record, args.source_root, args.output_root, args.verify_only)
90
+ groups += group_count
91
+ meshes += mesh_count
92
+ if selected and groups != len(selected):
93
+ missing = sorted(selected - {r.get('group_key') for r in iter_records(args.manifest)})
94
+ raise RuntimeError(f'requested group(s) were not found: {missing}')
95
+ print(json.dumps({'groups': groups, 'mesh_files': meshes, 'verify_only': args.verify_only}, indent=2))
96
+
97
+ if __name__ == '__main__':
98
+ main()
tools/pack_shards_from_bos.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Pack complete mesh edit groups into streamable TAR shards."""
3
+ from __future__ import annotations
4
+ import argparse
5
+ import copy
6
+ import hashlib
7
+ import json
8
+ import os
9
+ import shutil
10
+ import tarfile
11
+ from pathlib import Path
12
+ from typing import Any, Iterator
13
+
14
+ DEFAULT_MAX_SHARD_BYTES = 2 * 1024 * 1024 * 1024
15
+
16
+ def iter_records(manifest: Path) -> Iterator[dict[str, Any]]:
17
+ with manifest.open('r', encoding='utf-8') as handle:
18
+ for line_no, line in enumerate(handle, 1):
19
+ if not line.strip():
20
+ continue
21
+ try:
22
+ record = json.loads(line)
23
+ except json.JSONDecodeError as exc:
24
+ raise RuntimeError(f'{manifest}:{line_no}: invalid JSON: {exc}') from exc
25
+ yield record
26
+
27
+ def resolve_source(source_root: Path, relative_path: str) -> Path:
28
+ relative = Path(relative_path)
29
+ if relative.is_absolute() or '..' in relative.parts:
30
+ raise RuntimeError(f'unsafe manifest path: {relative_path}')
31
+ candidates = [source_root / relative]
32
+ if relative.parts and relative.parts[0] == 'meshes':
33
+ candidates.append(source_root / Path(*relative.parts[1:]))
34
+ for candidate in candidates:
35
+ if candidate.is_file():
36
+ return candidate
37
+ raise FileNotFoundError(f'source mesh not found for {relative_path}')
38
+
39
+ class HashReader:
40
+ def __init__(self, handle):
41
+ self.handle = handle
42
+ self.digest = hashlib.sha256()
43
+ def read(self, size: int = -1) -> bytes:
44
+ data = self.handle.read(size)
45
+ if data:
46
+ self.digest.update(data)
47
+ return data
48
+
49
+ def add_verified_file(tar: tarfile.TarFile, source: Path, member: str, expected: str) -> int:
50
+ info = tar.gettarinfo(str(source), arcname=member)
51
+ info.uid = 0
52
+ info.gid = 0
53
+ info.uname = ''
54
+ info.gname = ''
55
+ info.mtime = 0
56
+ info.mode = 0o644
57
+ with source.open('rb') as handle:
58
+ reader = HashReader(handle)
59
+ tar.addfile(info, reader)
60
+ actual = reader.digest.hexdigest()
61
+ if actual != expected:
62
+ raise RuntimeError(f'checksum mismatch for {member}: expected {expected}, got {actual}')
63
+ return info.size
64
+
65
+ def main() -> None:
66
+ parser = argparse.ArgumentParser(description=__doc__)
67
+ parser.add_argument('--manifest', type=Path, required=True, help='Sanitized three-stage JSONL manifest')
68
+ parser.add_argument('--source-root', type=Path, required=True, help='Mounted source mesh root or its parent dataset root')
69
+ parser.add_argument('--output-root', type=Path, required=True, help='Directory containing shards/ and manifest/')
70
+ parser.add_argument('--max-shard-bytes', type=int, default=DEFAULT_MAX_SHARD_BYTES, help='Target uncompressed payload per shard')
71
+ parser.add_argument('--max-groups', type=int, help='Pack only this many groups for a bounded run')
72
+ args = parser.parse_args()
73
+ if args.max_shard_bytes < 1:
74
+ parser.error('--max-shard-bytes must be positive')
75
+ if args.max_groups is not None and args.max_groups < 1:
76
+ parser.error('--max-groups must be positive')
77
+ shards_dir = args.output_root / 'shards'
78
+ manifest_dir = args.output_root / 'manifest'
79
+ shards_dir.mkdir(parents=True, exist_ok=True)
80
+ manifest_dir.mkdir(parents=True, exist_ok=True)
81
+ sharded_manifest = manifest_dir / 'three_stage_sharded.jsonl'
82
+ shard_index = manifest_dir / 'shard_index.jsonl'
83
+ if sharded_manifest.exists() or shard_index.exists() or any(shards_dir.iterdir()):
84
+ raise RuntimeError(f'output directory is not empty: {args.output_root}')
85
+ shard_number = 0
86
+ current_tar = None
87
+ current_payload = 0
88
+ current_shard_name = None
89
+ groups = 0
90
+ mesh_files = 0
91
+ shard_count = 0
92
+ try:
93
+ with sharded_manifest.open('w', encoding='utf-8') as manifest_out, shard_index.open('w', encoding='utf-8') as index_out:
94
+ for record in iter_records(args.manifest):
95
+ if args.max_groups is not None and groups >= args.max_groups:
96
+ break
97
+ group_key = record.get('group_key')
98
+ stages = record.get('stages')
99
+ if not isinstance(group_key, str) or not isinstance(stages, list):
100
+ raise RuntimeError('manifest record is missing group_key or stages')
101
+ sources = []
102
+ group_payload = 0
103
+ for stage in stages:
104
+ mesh = stage.get('mesh') if isinstance(stage, dict) else None
105
+ if not isinstance(mesh, dict):
106
+ raise RuntimeError(f'missing mesh metadata for {group_key}')
107
+ member = mesh.get('path')
108
+ expected = mesh.get('sha256')
109
+ if not isinstance(member, str) or not isinstance(expected, str):
110
+ raise RuntimeError(f'invalid mesh metadata for {group_key}')
111
+ source = resolve_source(args.source_root, member)
112
+ size = source.stat().st_size
113
+ sources.append((stage, mesh, member, expected, source, size))
114
+ group_payload += size
115
+ if current_tar is None or (current_payload and current_payload + group_payload > args.max_shard_bytes):
116
+ if current_tar is not None:
117
+ current_tar.close()
118
+ current_shard_name = f'shards/shard-{shard_number:06d}.tar'
119
+ current_tar = tarfile.open(args.output_root / current_shard_name, mode='w')
120
+ current_payload = 0
121
+ shard_number += 1
122
+ shard_count += 1
123
+ sharded = copy.deepcopy(record)
124
+ index_members = []
125
+ for stage_index, (stage, mesh, member, expected, source, _size) in enumerate(sources):
126
+ assert current_tar is not None and current_shard_name is not None
127
+ packed_size = add_verified_file(current_tar, source, member, expected)
128
+ current_payload += packed_size
129
+ mesh_out = sharded['stages'][stage_index]['mesh']
130
+ mesh_out['shard'] = current_shard_name
131
+ mesh_out['member'] = member
132
+ index_members.append({'stage': stage['stage'], 'member': member, 'sha256': expected})
133
+ mesh_files += 1
134
+ sharded_line = json.dumps(sharded, ensure_ascii=False, separators=(',', ':'))
135
+ manifest_out.write(sharded_line + '\n')
136
+ index_out.write(json.dumps({'group_key': group_key, 'shard': current_shard_name, 'members': index_members}, ensure_ascii=False, separators=(',', ':')) + '\n')
137
+ groups += 1
138
+ if groups % 100 == 0:
139
+ print(json.dumps({'progress_groups': groups, 'mesh_files': mesh_files, 'shards': shard_count, 'current_shard_payload_bytes': current_payload}), flush=True)
140
+ finally:
141
+ if current_tar is not None:
142
+ current_tar.close()
143
+ print(json.dumps({'groups': groups, 'mesh_files': mesh_files, 'shards': shard_count, 'target_shard_bytes': args.max_shard_bytes}, indent=2))
144
+
145
+ if __name__ == '__main__':
146
+ main()