parallelogram 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- parallelogram-0.2.0/.github/workflows/tests.yml +53 -0
- parallelogram-0.2.0/LICENSE +189 -0
- parallelogram-0.2.0/PKG-INFO +183 -0
- parallelogram-0.2.0/README.md +153 -0
- parallelogram-0.2.0/clean.jsonl +2 -0
- parallelogram-0.2.0/examples/broken.jsonl +8 -0
- parallelogram-0.2.0/examples/clean.jsonl +3 -0
- parallelogram-0.2.0/pyproject.toml +43 -0
- parallelogram-0.2.0/smoke.py +194 -0
- parallelogram-0.2.0/smoke_fix.py +258 -0
- parallelogram-0.2.0/src/parallelogram/__init__.py +2 -0
- parallelogram-0.2.0/src/parallelogram/cli.py +308 -0
- parallelogram-0.2.0/src/parallelogram/core/__init__.py +0 -0
- parallelogram-0.2.0/src/parallelogram/core/fixer.py +242 -0
- parallelogram-0.2.0/src/parallelogram/core/io.py +40 -0
- parallelogram-0.2.0/src/parallelogram/core/report.py +55 -0
- parallelogram-0.2.0/src/parallelogram/core/rules.py +101 -0
- parallelogram-0.2.0/src/parallelogram/core/runner.py +90 -0
- parallelogram-0.2.0/src/parallelogram/formats/__init__.py +0 -0
- parallelogram-0.2.0/src/parallelogram/formats/openai_chat.py +41 -0
- parallelogram-0.2.0/src/parallelogram/output/__init__.py +0 -0
- parallelogram-0.2.0/src/parallelogram/output/json_output.py +41 -0
- parallelogram-0.2.0/src/parallelogram/output/terminal.py +89 -0
- parallelogram-0.2.0/src/parallelogram/rules/__init__.py +0 -0
- parallelogram-0.2.0/src/parallelogram/rules/context_window.py +163 -0
- parallelogram-0.2.0/src/parallelogram/rules/duplicates.py +95 -0
- parallelogram-0.2.0/src/parallelogram/rules/empty_content.py +73 -0
- parallelogram-0.2.0/src/parallelogram/rules/encoding.py +114 -0
- parallelogram-0.2.0/src/parallelogram/rules/roles.py +95 -0
- parallelogram-0.2.0/src/parallelogram/rules/schema.py +106 -0
- parallelogram-0.2.0/tests/test_rules.py +166 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Phase 1 smoke (stdlib-only, no install)
|
|
25
|
+
run: python smoke.py
|
|
26
|
+
|
|
27
|
+
- name: Phase 2 fix-tier smoke (stdlib-only, no install)
|
|
28
|
+
run: python smoke_fix.py
|
|
29
|
+
|
|
30
|
+
- name: Install with dev extras
|
|
31
|
+
run: |
|
|
32
|
+
pip install --upgrade pip
|
|
33
|
+
pip install -e ".[dev]"
|
|
34
|
+
|
|
35
|
+
- name: Run pytest
|
|
36
|
+
run: pytest tests/ -v
|
|
37
|
+
|
|
38
|
+
- name: CLI sanity check (Phase 1)
|
|
39
|
+
run: |
|
|
40
|
+
parallelogram --help
|
|
41
|
+
parallelogram check examples/clean.jsonl
|
|
42
|
+
# broken.jsonl is expected to exit 2; invert so the workflow passes
|
|
43
|
+
! parallelogram check examples/broken.jsonl
|
|
44
|
+
|
|
45
|
+
- name: CLI sanity check (Phase 2 --fix)
|
|
46
|
+
run: |
|
|
47
|
+
# --fix on broken.jsonl should drop unfixable records but emit clean ones,
|
|
48
|
+
# exiting 1 (partial fix). The `|| [ $? -eq 1 ]` pattern lets exit 1 pass.
|
|
49
|
+
parallelogram check examples/broken.jsonl --fix --dry-run || [ $? -eq 1 ]
|
|
50
|
+
parallelogram check examples/broken.jsonl --fix --output /tmp/cleaned.jsonl || [ $? -eq 1 ]
|
|
51
|
+
test -s /tmp/cleaned.jsonl
|
|
52
|
+
# The repaired output must itself validate clean
|
|
53
|
+
parallelogram check /tmp/cleaned.jsonl
|
|
@@ -0,0 +1,189 @@
|
|
|
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 describing the origin of the Work and
|
|
141
|
+
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 accept support,
|
|
167
|
+
warranty, indemnity, or other liability obligations and/or rights
|
|
168
|
+
consistent with this License. However, in accepting such obligations,
|
|
169
|
+
You may act only on Your own behalf and on Your sole responsibility,
|
|
170
|
+
not on behalf of any other Contributor, and only if You agree to
|
|
171
|
+
indemnify, defend, and hold each Contributor harmless for any
|
|
172
|
+
liability incurred by, or claims asserted against, such Contributor
|
|
173
|
+
by reason of your accepting any such warranty or additional liability.
|
|
174
|
+
|
|
175
|
+
END OF TERMS AND CONDITIONS
|
|
176
|
+
|
|
177
|
+
Copyright 2026 Thatayotlhe Tsenang
|
|
178
|
+
|
|
179
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
180
|
+
you may not use this file except in compliance with the License.
|
|
181
|
+
You may obtain a copy of the License at
|
|
182
|
+
|
|
183
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
184
|
+
|
|
185
|
+
Unless required by applicable law or agreed to in writing, software
|
|
186
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
187
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
188
|
+
See the License for the specific language governing permissions and
|
|
189
|
+
limitations under the License.
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: parallelogram
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Strict validator for fine-tuning datasets. Run before you train.
|
|
5
|
+
Project-URL: Homepage, https://parallelogram.dev
|
|
6
|
+
Author-email: Thatayotlhe Tsenang <tsenangthatayotlhe04@gmail.com>
|
|
7
|
+
Maintainer-email: Thatayotlhe Tsenang <tsenangthatayotlhe04@gmail.com>
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: dataset,fine-tuning,linter,llm,validation
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: rich>=13.7
|
|
23
|
+
Requires-Dist: typer>=0.12
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
26
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
27
|
+
Provides-Extra: tokenizer
|
|
28
|
+
Requires-Dist: tokenizers>=0.15; extra == 'tokenizer'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# parallelogram
|
|
32
|
+
|
|
33
|
+
> Strict validator for fine-tuning datasets. Run it before you train.
|
|
34
|
+
|
|
35
|
+
Every fine-tuning framework assumes your data is clean. None of them verify it.
|
|
36
|
+
Axolotl will start a run on malformed data and either crash mid-way or — worse —
|
|
37
|
+
complete silently while producing a broken model. TRL will truncate samples that
|
|
38
|
+
exceed the context window without telling you. Unsloth will train on duplicates
|
|
39
|
+
that cause your model to memorize instead of generalize.
|
|
40
|
+
|
|
41
|
+
`parallelogram` sits between your raw dataset and your training run. It hard-blocks
|
|
42
|
+
on anything that would silently corrupt training. **If it exits 0 with all rules enabled,
|
|
43
|
+
your run won't fail because of data.**
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install parallelogram
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
For the context-window check, also install the tokenizer extras:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install 'parallelogram[tokenizer]'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Use
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
parallelogram check data.jsonl
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
With a tokenizer for context-window validation:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
parallelogram check data.jsonl \
|
|
67
|
+
--tokenizer meta-llama/Llama-3-8B \
|
|
68
|
+
--max-seq-len 8192
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Write only the clean records to a new file:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
parallelogram check data.jsonl --output clean.jsonl
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## `--fix` — mechanical repair
|
|
78
|
+
|
|
79
|
+
When `parallelogram check` finds errors, `--fix` attempts to repair what it can without
|
|
80
|
+
touching the model. Mechanical fixes are free, local, and require no network call.
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
parallelogram check data.jsonl --fix --output clean.jsonl
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Fixes applied in order:
|
|
87
|
+
|
|
88
|
+
1. **encoding** — strip BOM markers, replace mojibake (`don’t` → `don't`)
|
|
89
|
+
2. **empty-content** — drop empty/whitespace-only message turns
|
|
90
|
+
3. **context-window** — truncate the longest user message until the record fits
|
|
91
|
+
4. **duplicates** — keep the first occurrence, drop subsequent
|
|
92
|
+
|
|
93
|
+
After fixes are applied, the dataset is **re-validated**. Anything still erroring is
|
|
94
|
+
dropped from the output. The CLI tells you exactly what was unchanged, fixed, and
|
|
95
|
+
dropped:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
✓ encoding · 4 fixes
|
|
99
|
+
✓ duplicates · 12 fixes
|
|
100
|
+
|
|
101
|
+
✗ dropped:
|
|
102
|
+
data.jsonl:23 → roles (unfixable)
|
|
103
|
+
data.jsonl:147 → schema (unfixable)
|
|
104
|
+
|
|
105
|
+
547 records 531 unchanged 4 fixed 11 dropped 1 unparseable
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Errors that need understanding the content (broken role sequences, incomplete
|
|
109
|
+
assistant turns) are not fixable mechanically. These will be addressed by a hosted
|
|
110
|
+
SLM tier in a future release. For now, they are dropped.
|
|
111
|
+
|
|
112
|
+
Use `--dry-run` to preview without writing:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
parallelogram check data.jsonl --fix --dry-run
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## `--disable` and the exit-0 guarantee
|
|
119
|
+
|
|
120
|
+
Rules can be disabled by id (e.g. `--disable encoding`), but with three constraints:
|
|
121
|
+
|
|
122
|
+
- The `schema` rule cannot be disabled. Every other rule depends on its structural
|
|
123
|
+
guarantees, and disabling it would let other rules silently no-op on malformed records.
|
|
124
|
+
- Unknown rule ids are rejected. Typos like `--disable encding` exit non-zero with a
|
|
125
|
+
list of valid options rather than silently doing nothing.
|
|
126
|
+
- Whenever any rule is disabled, a loud stderr warning names exactly which ones, and
|
|
127
|
+
reminds you that the exit-0 guarantee no longer applies. The terminal output and
|
|
128
|
+
JSON report (`disabled_rules` field) both surface this so CI tooling can refuse to
|
|
129
|
+
merge a PR that disabled rules.
|
|
130
|
+
|
|
131
|
+
The guarantee is precise: **a clean exit with all rules enabled** means your run won't
|
|
132
|
+
fail because of data. A clean exit with rules disabled means only that the rules you
|
|
133
|
+
left enabled passed — which may or may not be enough.
|
|
134
|
+
|
|
135
|
+
## Options
|
|
136
|
+
|
|
137
|
+
| Flag | Description |
|
|
138
|
+
|------|-------------|
|
|
139
|
+
| `--format`, `-f` | Dataset format. Only `openai-chat` in v0.1. |
|
|
140
|
+
| `--tokenizer`, `-t` | HuggingFace tokenizer name. Required for context-window check. |
|
|
141
|
+
| `--max-seq-len` | Token budget per record (default 4096). |
|
|
142
|
+
| `--output`, `-o` | Write error-free records to this file. With `--fix`, writes the repaired dataset. |
|
|
143
|
+
| `--fix` | Attempt mechanical repair of fixable issues. |
|
|
144
|
+
| `--dry-run` | With `--fix`, report what would change without writing. |
|
|
145
|
+
| `--json` | Machine-readable report on stdout. |
|
|
146
|
+
| `--disable` | Disable a rule by id. Repeatable. |
|
|
147
|
+
| `--no-color` | Plain output. |
|
|
148
|
+
|
|
149
|
+
## Exit codes
|
|
150
|
+
|
|
151
|
+
| Code | Meaning (check) | Meaning (--fix) |
|
|
152
|
+
|------|---------|---------|
|
|
153
|
+
| `0` | Clean. | All records emitted clean. |
|
|
154
|
+
| `1` | Warnings only. | Some records dropped (partial fix). |
|
|
155
|
+
| `2` | Errors. | Nothing fixable. |
|
|
156
|
+
|
|
157
|
+
These map directly to CI gates without any extra wiring.
|
|
158
|
+
|
|
159
|
+
## Rules
|
|
160
|
+
|
|
161
|
+
| id | severity | catches |
|
|
162
|
+
|----|----------|---------|
|
|
163
|
+
| `schema` | error | malformed records, missing fields, wrong types |
|
|
164
|
+
| `roles` | error | bad role sequences (system out of place, no alternation, doesn't end on assistant) |
|
|
165
|
+
| `empty-content` | error | empty or whitespace-only message content |
|
|
166
|
+
| `context-window` | error | records exceeding `max_seq_len` (TRL truncates these silently) |
|
|
167
|
+
| `duplicates` | error | exact-content duplicate records (memorization → poor generalization) |
|
|
168
|
+
| `encoding` | warning | BOM markers, mojibake patterns |
|
|
169
|
+
|
|
170
|
+
## Status
|
|
171
|
+
|
|
172
|
+
v0.2 — solo dev, local, pre-training run. No telemetry, no network, no upload boundary.
|
|
173
|
+
|
|
174
|
+
## Roadmap
|
|
175
|
+
|
|
176
|
+
- ShareGPT and raw-completion formats
|
|
177
|
+
- ~~`--fix` mechanical tier (dedupe, truncate, normalize encoding)~~ ✓ shipped in v0.2
|
|
178
|
+
- Opt-in anonymized error-type analytics (informs SLM tier scope)
|
|
179
|
+
- `--fix --slm` paid hosted tier — repairs broken role sequences, incomplete turns
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
Apache-2.0
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# parallelogram
|
|
2
|
+
|
|
3
|
+
> Strict validator for fine-tuning datasets. Run it before you train.
|
|
4
|
+
|
|
5
|
+
Every fine-tuning framework assumes your data is clean. None of them verify it.
|
|
6
|
+
Axolotl will start a run on malformed data and either crash mid-way or — worse —
|
|
7
|
+
complete silently while producing a broken model. TRL will truncate samples that
|
|
8
|
+
exceed the context window without telling you. Unsloth will train on duplicates
|
|
9
|
+
that cause your model to memorize instead of generalize.
|
|
10
|
+
|
|
11
|
+
`parallelogram` sits between your raw dataset and your training run. It hard-blocks
|
|
12
|
+
on anything that would silently corrupt training. **If it exits 0 with all rules enabled,
|
|
13
|
+
your run won't fail because of data.**
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install parallelogram
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
For the context-window check, also install the tokenizer extras:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install 'parallelogram[tokenizer]'
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Use
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
parallelogram check data.jsonl
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
With a tokenizer for context-window validation:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
parallelogram check data.jsonl \
|
|
37
|
+
--tokenizer meta-llama/Llama-3-8B \
|
|
38
|
+
--max-seq-len 8192
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Write only the clean records to a new file:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
parallelogram check data.jsonl --output clean.jsonl
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## `--fix` — mechanical repair
|
|
48
|
+
|
|
49
|
+
When `parallelogram check` finds errors, `--fix` attempts to repair what it can without
|
|
50
|
+
touching the model. Mechanical fixes are free, local, and require no network call.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
parallelogram check data.jsonl --fix --output clean.jsonl
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Fixes applied in order:
|
|
57
|
+
|
|
58
|
+
1. **encoding** — strip BOM markers, replace mojibake (`don’t` → `don't`)
|
|
59
|
+
2. **empty-content** — drop empty/whitespace-only message turns
|
|
60
|
+
3. **context-window** — truncate the longest user message until the record fits
|
|
61
|
+
4. **duplicates** — keep the first occurrence, drop subsequent
|
|
62
|
+
|
|
63
|
+
After fixes are applied, the dataset is **re-validated**. Anything still erroring is
|
|
64
|
+
dropped from the output. The CLI tells you exactly what was unchanged, fixed, and
|
|
65
|
+
dropped:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
✓ encoding · 4 fixes
|
|
69
|
+
✓ duplicates · 12 fixes
|
|
70
|
+
|
|
71
|
+
✗ dropped:
|
|
72
|
+
data.jsonl:23 → roles (unfixable)
|
|
73
|
+
data.jsonl:147 → schema (unfixable)
|
|
74
|
+
|
|
75
|
+
547 records 531 unchanged 4 fixed 11 dropped 1 unparseable
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Errors that need understanding the content (broken role sequences, incomplete
|
|
79
|
+
assistant turns) are not fixable mechanically. These will be addressed by a hosted
|
|
80
|
+
SLM tier in a future release. For now, they are dropped.
|
|
81
|
+
|
|
82
|
+
Use `--dry-run` to preview without writing:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
parallelogram check data.jsonl --fix --dry-run
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## `--disable` and the exit-0 guarantee
|
|
89
|
+
|
|
90
|
+
Rules can be disabled by id (e.g. `--disable encoding`), but with three constraints:
|
|
91
|
+
|
|
92
|
+
- The `schema` rule cannot be disabled. Every other rule depends on its structural
|
|
93
|
+
guarantees, and disabling it would let other rules silently no-op on malformed records.
|
|
94
|
+
- Unknown rule ids are rejected. Typos like `--disable encding` exit non-zero with a
|
|
95
|
+
list of valid options rather than silently doing nothing.
|
|
96
|
+
- Whenever any rule is disabled, a loud stderr warning names exactly which ones, and
|
|
97
|
+
reminds you that the exit-0 guarantee no longer applies. The terminal output and
|
|
98
|
+
JSON report (`disabled_rules` field) both surface this so CI tooling can refuse to
|
|
99
|
+
merge a PR that disabled rules.
|
|
100
|
+
|
|
101
|
+
The guarantee is precise: **a clean exit with all rules enabled** means your run won't
|
|
102
|
+
fail because of data. A clean exit with rules disabled means only that the rules you
|
|
103
|
+
left enabled passed — which may or may not be enough.
|
|
104
|
+
|
|
105
|
+
## Options
|
|
106
|
+
|
|
107
|
+
| Flag | Description |
|
|
108
|
+
|------|-------------|
|
|
109
|
+
| `--format`, `-f` | Dataset format. Only `openai-chat` in v0.1. |
|
|
110
|
+
| `--tokenizer`, `-t` | HuggingFace tokenizer name. Required for context-window check. |
|
|
111
|
+
| `--max-seq-len` | Token budget per record (default 4096). |
|
|
112
|
+
| `--output`, `-o` | Write error-free records to this file. With `--fix`, writes the repaired dataset. |
|
|
113
|
+
| `--fix` | Attempt mechanical repair of fixable issues. |
|
|
114
|
+
| `--dry-run` | With `--fix`, report what would change without writing. |
|
|
115
|
+
| `--json` | Machine-readable report on stdout. |
|
|
116
|
+
| `--disable` | Disable a rule by id. Repeatable. |
|
|
117
|
+
| `--no-color` | Plain output. |
|
|
118
|
+
|
|
119
|
+
## Exit codes
|
|
120
|
+
|
|
121
|
+
| Code | Meaning (check) | Meaning (--fix) |
|
|
122
|
+
|------|---------|---------|
|
|
123
|
+
| `0` | Clean. | All records emitted clean. |
|
|
124
|
+
| `1` | Warnings only. | Some records dropped (partial fix). |
|
|
125
|
+
| `2` | Errors. | Nothing fixable. |
|
|
126
|
+
|
|
127
|
+
These map directly to CI gates without any extra wiring.
|
|
128
|
+
|
|
129
|
+
## Rules
|
|
130
|
+
|
|
131
|
+
| id | severity | catches |
|
|
132
|
+
|----|----------|---------|
|
|
133
|
+
| `schema` | error | malformed records, missing fields, wrong types |
|
|
134
|
+
| `roles` | error | bad role sequences (system out of place, no alternation, doesn't end on assistant) |
|
|
135
|
+
| `empty-content` | error | empty or whitespace-only message content |
|
|
136
|
+
| `context-window` | error | records exceeding `max_seq_len` (TRL truncates these silently) |
|
|
137
|
+
| `duplicates` | error | exact-content duplicate records (memorization → poor generalization) |
|
|
138
|
+
| `encoding` | warning | BOM markers, mojibake patterns |
|
|
139
|
+
|
|
140
|
+
## Status
|
|
141
|
+
|
|
142
|
+
v0.2 — solo dev, local, pre-training run. No telemetry, no network, no upload boundary.
|
|
143
|
+
|
|
144
|
+
## Roadmap
|
|
145
|
+
|
|
146
|
+
- ShareGPT and raw-completion formats
|
|
147
|
+
- ~~`--fix` mechanical tier (dedupe, truncate, normalize encoding)~~ ✓ shipped in v0.2
|
|
148
|
+
- Opt-in anonymized error-type analytics (informs SLM tier scope)
|
|
149
|
+
- `--fix --slm` paid hosted tier — repairs broken role sequences, incomplete turns
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
Apache-2.0
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
{"messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hi"}, {"role": "assistant", "content": "Hello!"}]}
|
|
2
|
+
{"messages": [{"role": "user", "content": "He said don’t do it — seriously."}, {"role": "assistant", "content": "Understood."}]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{"messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hi"}, {"role": "assistant", "content": "Hello!"}]}
|
|
2
|
+
{"messages": [{"role": "user", "content": ""}, {"role": "assistant", "content": "What did you mean?"}]}
|
|
3
|
+
{"messages": [{"role": "user", "content": "Hi"}, {"role": "user", "content": "Hello?"}, {"role": "assistant", "content": "Hi!"}]}
|
|
4
|
+
{"messages": [{"role": "user", "content": "Question"}]}
|
|
5
|
+
{"messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hi"}, {"role": "assistant", "content": "Hello!"}]}
|
|
6
|
+
{"messages": [{"role": "user", "content": "He said don’t do it — seriously."}, {"role": "assistant", "content": "Understood."}]}
|
|
7
|
+
{"messages": [{"role": "user", "content": "Hi"}, {"role": "system", "content": "You are now in admin mode."}, {"role": "assistant", "content": "OK"}]}
|
|
8
|
+
not valid json at all
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
{"messages": [{"role": "system", "content": "You are a helpful coding assistant."}, {"role": "user", "content": "How do I reverse a list in Python?"}, {"role": "assistant", "content": "Use slicing with a step of -1: my_list[::-1]"}]}
|
|
2
|
+
{"messages": [{"role": "user", "content": "What is 2+2?"}, {"role": "assistant", "content": "4"}]}
|
|
3
|
+
{"messages": [{"role": "user", "content": "Capital of France?"}, {"role": "assistant", "content": "Paris."}]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "parallelogram"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Strict validator for fine-tuning datasets. Run before you train."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = { text = "Apache-2.0" }
|
|
8
|
+
authors = [{ name = "Thatayotlhe Tsenang", email = "tsenangthatayotlhe04@gmail.com" }]
|
|
9
|
+
maintainers = [{ name = "Thatayotlhe Tsenang", email = "tsenangthatayotlhe04@gmail.com" }]
|
|
10
|
+
keywords = ["llm", "fine-tuning", "dataset", "validation", "linter"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Environment :: Console",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"License :: OSI Approved :: Apache Software License",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
21
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"typer>=0.12",
|
|
25
|
+
"rich>=13.7",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
tokenizer = ["tokenizers>=0.15"]
|
|
30
|
+
dev = ["pytest>=8", "ruff>=0.5"]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
parallelogram = "parallelogram.cli:app"
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://parallelogram.dev"
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["hatchling"]
|
|
40
|
+
build-backend = "hatchling.build"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["src/parallelogram"]
|