ninmeni 0.1.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.
- ninmeni-0.1.0/LICENSE +201 -0
- ninmeni-0.1.0/MANIFEST.in +8 -0
- ninmeni-0.1.0/PKG-INFO +66 -0
- ninmeni-0.1.0/README.md +44 -0
- ninmeni-0.1.0/configs/contoh_75m.yaml +35 -0
- ninmeni-0.1.0/docs/antarmuka-model.md +67 -0
- ninmeni-0.1.0/docs/kurikulum.md +28 -0
- ninmeni-0.1.0/examples/curriculum/pretraining_contoh.jsonl +4 -0
- ninmeni-0.1.0/examples/curriculum/sft_contoh.jsonl +4 -0
- ninmeni-0.1.0/model/reference_model.py +144 -0
- ninmeni-0.1.0/ninmeni.egg-info/PKG-INFO +66 -0
- ninmeni-0.1.0/ninmeni.egg-info/SOURCES.txt +25 -0
- ninmeni-0.1.0/ninmeni.egg-info/dependency_links.txt +1 -0
- ninmeni-0.1.0/ninmeni.egg-info/requires.txt +5 -0
- ninmeni-0.1.0/ninmeni.egg-info/top_level.txt +1 -0
- ninmeni-0.1.0/nmu/__init__.py +20 -0
- ninmeni-0.1.0/nmu/codec.py +137 -0
- ninmeni-0.1.0/nmu/errors.py +37 -0
- ninmeni-0.1.0/nmu/nmu_v1.json +1 -0
- ninmeni-0.1.0/pipeline/build_shards.py +218 -0
- ninmeni-0.1.0/pyproject.toml +33 -0
- ninmeni-0.1.0/registry/nmu_v1.json +1 -0
- ninmeni-0.1.0/requirements.txt +5 -0
- ninmeni-0.1.0/setup.cfg +4 -0
- ninmeni-0.1.0/training/native_utils.py +200 -0
- ninmeni-0.1.0/training/sft_native.py +386 -0
- ninmeni-0.1.0/training/train_unified_native.py +223 -0
ninmeni-0.1.0/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 [yyyy] [name of copyright owner]
|
|
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.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
include LICENSE README.md requirements.txt
|
|
2
|
+
recursive-include docs *.md
|
|
3
|
+
recursive-include configs *.yaml
|
|
4
|
+
recursive-include examples *.jsonl
|
|
5
|
+
recursive-include registry *.json
|
|
6
|
+
recursive-include training *.py
|
|
7
|
+
recursive-include pipeline *.py
|
|
8
|
+
recursive-include model *.py
|
ninmeni-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ninmeni
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: NINMENI - framework model bahasa native Indonesia. Paradigma NMU: 1 karakter = 1 ID, ruang karakter statis universal, tanpa UNK.
|
|
5
|
+
Author-email: Emylton Leunufna <emylleons8@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://ninmeni.net
|
|
8
|
+
Keywords: nlp,bahasa-indonesia,character-level,language-model,tokenizer-free
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Natural Language :: Indonesian
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Requires-Python: >=3.9
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: numpy
|
|
18
|
+
Provides-Extra: train
|
|
19
|
+
Requires-Dist: torch>=2.4; extra == "train"
|
|
20
|
+
Requires-Dist: pyyaml; extra == "train"
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# NINMENI — Framework Model Bahasa Native Indonesia
|
|
24
|
+
|
|
25
|
+
**NINMENI** adalah kerangka riset dan rekayasa untuk membangun model bahasa yang
|
|
26
|
+
native terhadap bahasa Indonesia, dari lapisan paling dasar.
|
|
27
|
+
|
|
28
|
+
Hierarki: **framework NINMENI → paradigma NMU → model (contoh: Veyra)**.
|
|
29
|
+
|
|
30
|
+
- **NMU (Native Meaning Unit)** — paradigma representasi: satu karakter = satu
|
|
31
|
+
identitas tetap, di ruang karakter statis universal. Tanpa segmentasi sub-kata,
|
|
32
|
+
tanpa UNK. Bahasa Indonesia hidup dari imbuhan; dengan membaca per karakter, akar
|
|
33
|
+
kata selalu tampak utuh di setiap turunannya — model menemukan pola imbuhan sendiri.
|
|
34
|
+
- **Veyra** — model pertama yang lahir dari kerangka ini (beta).
|
|
35
|
+
|
|
36
|
+
## Isi repo
|
|
37
|
+
```
|
|
38
|
+
nmu/ codec NMU (paket paradigma) (encode/decode 1 karakter = 1 ID, registry-driven)
|
|
39
|
+
registry/ ruang karakter statis (nmu_v1.json)
|
|
40
|
+
model/ model REFERENSI (decoder polos) — titik colok arsitektur Anda; BUKAN arsitektur Veyra
|
|
41
|
+
training/ loop pelatihan unified (pretraining + SFT satu loop) + sampler shard
|
|
42
|
+
pipeline/ build_shards.py — teks JSONL -> shard ids (mmap-able)
|
|
43
|
+
configs/ contoh konfigurasi
|
|
44
|
+
docs/ panduan kurikulum data
|
|
45
|
+
examples/ contoh format kurikulum (pretraining & SFT)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Mulai cepat
|
|
49
|
+
1. Siapkan korpus JSONL `{"teks": "..."}` (lihat `examples/curriculum/`).
|
|
50
|
+
2. Shardize: `python pipeline/build_shards.py --inputs korpus.jsonl --out data/shards`
|
|
51
|
+
3. Latih: `python -m training.train_unified_native --config configs/contoh_75m.yaml \
|
|
52
|
+
--shards data/shards/train --sft data/sft_train.jsonl --registry registry/nmu_v1.json`
|
|
53
|
+
|
|
54
|
+
## Status & batas yang jujur
|
|
55
|
+
Proyek ini dibuka bertahap. Kode di sini adalah pipeline yang benar-benar dipakai
|
|
56
|
+
membangun Veyra 75M (beta) — bukan kode demonstrasi. Yang TIDAK ada di repo ini:
|
|
57
|
+
bobot model, arsitektur internal Veyra (model/ berisi referensi polos sebagai titik
|
|
58
|
+
colok — lihat docs/antarmuka-model.md), korpus pelatihan, dan catatan riset internal. Evaluasi menyeluruh
|
|
59
|
+
menunggu dokumentasi teknis rilis penuh.
|
|
60
|
+
|
|
61
|
+
## Kontribusi & lisensi
|
|
62
|
+
Kode di repo ini dilisensikan di bawah **Apache License 2.0** (lihat `LICENSE`).
|
|
63
|
+
Kontribusi dipersilakan melalui issue / pull request.
|
|
64
|
+
|
|
65
|
+
## Kontak
|
|
66
|
+
Emylton Leunufna — pencipta framework NINMENI & paradigma NMU — `emylleons8@gmail.com`
|
ninmeni-0.1.0/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# NINMENI — Framework Model Bahasa Native Indonesia
|
|
2
|
+
|
|
3
|
+
**NINMENI** adalah kerangka riset dan rekayasa untuk membangun model bahasa yang
|
|
4
|
+
native terhadap bahasa Indonesia, dari lapisan paling dasar.
|
|
5
|
+
|
|
6
|
+
Hierarki: **framework NINMENI → paradigma NMU → model (contoh: Veyra)**.
|
|
7
|
+
|
|
8
|
+
- **NMU (Native Meaning Unit)** — paradigma representasi: satu karakter = satu
|
|
9
|
+
identitas tetap, di ruang karakter statis universal. Tanpa segmentasi sub-kata,
|
|
10
|
+
tanpa UNK. Bahasa Indonesia hidup dari imbuhan; dengan membaca per karakter, akar
|
|
11
|
+
kata selalu tampak utuh di setiap turunannya — model menemukan pola imbuhan sendiri.
|
|
12
|
+
- **Veyra** — model pertama yang lahir dari kerangka ini (beta).
|
|
13
|
+
|
|
14
|
+
## Isi repo
|
|
15
|
+
```
|
|
16
|
+
nmu/ codec NMU (paket paradigma) (encode/decode 1 karakter = 1 ID, registry-driven)
|
|
17
|
+
registry/ ruang karakter statis (nmu_v1.json)
|
|
18
|
+
model/ model REFERENSI (decoder polos) — titik colok arsitektur Anda; BUKAN arsitektur Veyra
|
|
19
|
+
training/ loop pelatihan unified (pretraining + SFT satu loop) + sampler shard
|
|
20
|
+
pipeline/ build_shards.py — teks JSONL -> shard ids (mmap-able)
|
|
21
|
+
configs/ contoh konfigurasi
|
|
22
|
+
docs/ panduan kurikulum data
|
|
23
|
+
examples/ contoh format kurikulum (pretraining & SFT)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Mulai cepat
|
|
27
|
+
1. Siapkan korpus JSONL `{"teks": "..."}` (lihat `examples/curriculum/`).
|
|
28
|
+
2. Shardize: `python pipeline/build_shards.py --inputs korpus.jsonl --out data/shards`
|
|
29
|
+
3. Latih: `python -m training.train_unified_native --config configs/contoh_75m.yaml \
|
|
30
|
+
--shards data/shards/train --sft data/sft_train.jsonl --registry registry/nmu_v1.json`
|
|
31
|
+
|
|
32
|
+
## Status & batas yang jujur
|
|
33
|
+
Proyek ini dibuka bertahap. Kode di sini adalah pipeline yang benar-benar dipakai
|
|
34
|
+
membangun Veyra 75M (beta) — bukan kode demonstrasi. Yang TIDAK ada di repo ini:
|
|
35
|
+
bobot model, arsitektur internal Veyra (model/ berisi referensi polos sebagai titik
|
|
36
|
+
colok — lihat docs/antarmuka-model.md), korpus pelatihan, dan catatan riset internal. Evaluasi menyeluruh
|
|
37
|
+
menunggu dokumentasi teknis rilis penuh.
|
|
38
|
+
|
|
39
|
+
## Kontribusi & lisensi
|
|
40
|
+
Kode di repo ini dilisensikan di bawah **Apache License 2.0** (lihat `LICENSE`).
|
|
41
|
+
Kontribusi dipersilakan melalui issue / pull request.
|
|
42
|
+
|
|
43
|
+
## Kontak
|
|
44
|
+
Emylton Leunufna — pencipta framework NINMENI & paradigma NMU — `emylleons8@gmail.com`
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Contoh konfigurasi ~75M — pretrain + SFT satu loop (muat di GPU konsumen ~8GB).
|
|
2
|
+
#
|
|
3
|
+
# Per step: ratio r ramp ratio0->ratio1, pilih SFT vs pretrain batch.
|
|
4
|
+
# - pretrain batch: seq=1024 (sampling acak shards), loss = model.loss(x) SHIFTED
|
|
5
|
+
# - SFT batch: max_len=2048 (build_example), loss = sft_loss SHIFTED + IGNORE mask
|
|
6
|
+
#
|
|
7
|
+
# Microbatch terpisah per tipe batch (SFT lebih kecil karena sekuens 2x lebih panjang).
|
|
8
|
+
|
|
9
|
+
run_name: veyra-native
|
|
10
|
+
|
|
11
|
+
model:
|
|
12
|
+
d_model: 768
|
|
13
|
+
n_layers: 12
|
|
14
|
+
n_heads: 12
|
|
15
|
+
n_kv_heads: 4
|
|
16
|
+
mlp_ratio: 4.0
|
|
17
|
+
rope_theta: 10000.0
|
|
18
|
+
grad_checkpoint: true
|
|
19
|
+
|
|
20
|
+
train:
|
|
21
|
+
pretrain_seq_len: 1024 # window pretrain
|
|
22
|
+
sft_max_len: 2048 # cap panjang SFT
|
|
23
|
+
# Throughput: sesuaikan microbatch dgn memori GPU Anda;
|
|
24
|
+
# nilai di bawah = titik awal yang wajar utk ~8GB.
|
|
25
|
+
microbatch_pretrain: 4 # T=1024
|
|
26
|
+
microbatch_sft: 2 # T=2048
|
|
27
|
+
grad_accum: 16
|
|
28
|
+
ratio0: 0.15 # awal: 15% SFT, 85% pretrain
|
|
29
|
+
ratio1: 0.35 # akhir: 35% SFT, 65% pretrain
|
|
30
|
+
lr: 3.0e-4
|
|
31
|
+
warmup: 300
|
|
32
|
+
optimizer: adam8bit
|
|
33
|
+
precision: bf16
|
|
34
|
+
ckpt_every: 200
|
|
35
|
+
time_budget_sec: 86400 # budget waktu run (detik)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Antarmuka Model — Kontrak yang Dituntut Pipeline
|
|
2
|
+
|
|
3
|
+
Repo ini menyertakan `model/reference_model.py` — decoder karakter-level yang
|
|
4
|
+
sengaja polos. Ia BUKAN arsitektur Veyra; ia titik colok. Arsitektur Anda sendiri
|
|
5
|
+
bisa langsung dipakai trainer selama memenuhi kontrak berikut.
|
|
6
|
+
|
|
7
|
+
## 1. Config (dataclass)
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
@dataclass
|
|
11
|
+
class MyConfig:
|
|
12
|
+
ukuran_ruang: int # ukuran ruang karakter — diisi trainer dari registry (codec.ukuran_ruang)
|
|
13
|
+
pad_id: int # diisi trainer dari registry (codec.pad_id)
|
|
14
|
+
# ... field lain = kunci di blok `model:` pada configs/*.yaml
|
|
15
|
+
grad_checkpoint: bool = False # dibaca trainer untuk log
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Trainer memvalidasi kunci yaml terhadap `fields(Config)` — kunci yang tidak
|
|
19
|
+
dikenal dibuang dengan peringatan. Jadi: field config Anda = kunci yaml Anda.
|
|
20
|
+
|
|
21
|
+
## 2. Model
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
class MyModel(nn.Module):
|
|
25
|
+
def __init__(self, cfg: MyConfig): ...
|
|
26
|
+
# WAJIB: simpan config di atribut ini (dipakai sft_loss & checkpointing)
|
|
27
|
+
self.cfg = cfg
|
|
28
|
+
|
|
29
|
+
def forward(self, x): # x: LongTensor [B, T] berisi ID karakter
|
|
30
|
+
return logits # FloatTensor [B, T, ukuran_ruang]
|
|
31
|
+
|
|
32
|
+
def loss(self, x): # objective pretraining
|
|
33
|
+
# WAJIB SHIFTED: logits[:, :-1] vs x[:, 1:]
|
|
34
|
+
# Loss tanpa shift = model belajar MENYALIN, bukan memprediksi —
|
|
35
|
+
# ini kelas bug yang diam dan mahal. Uji: loss awal harus ~ln(ukuran ruang).
|
|
36
|
+
...
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 3. Aturan native yang tidak boleh dilanggar
|
|
40
|
+
|
|
41
|
+
- **Input = deretan ID karakter mentah** dari codec (1 karakter = 1 ID).
|
|
42
|
+
Jangan menambahkan segmentasi/penggabungan apa pun sebelum pemetaan ID→vektor
|
|
43
|
+
di dalam model — kalau Anda ingin kompresi, letakkan DI DALAM model sebagai
|
|
44
|
+
bagian arsitektur.
|
|
45
|
+
- **Tanpa UNK**: ukuran_ruang datang dari registry; semua ID valid.
|
|
46
|
+
- **PAD**: tidak dilatih (ignore_index) dan tidak dilihat attention.
|
|
47
|
+
- **Checkpoint**: trainer menyimpan `model.state_dict()` + config dict —
|
|
48
|
+
pastikan arsitektur Anda dapat direkonstruksi dari config-nya saja.
|
|
49
|
+
|
|
50
|
+
## 4. Menghubungkan ke trainer
|
|
51
|
+
|
|
52
|
+
Satu baris di `training/train_unified_native.py`:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from model.reference_model import VeyraNativeModel, VeyraNativeConfig, count_params
|
|
56
|
+
# ganti menjadi:
|
|
57
|
+
from model.arsitektur_anda import VeyraNativeModel, VeyraNativeConfig, count_params
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
(Ekspor alias dengan nama yang sama, atau ubah ketiga nama di trainer.)
|
|
61
|
+
|
|
62
|
+
## 5. Cara menilai model native (kacamata yang benar)
|
|
63
|
+
|
|
64
|
+
Model karakter-level punya ritme belajarnya sendiri. Metrik yang wajar dipantau:
|
|
65
|
+
bits/char (BPC) pada validasi — bukan membandingkan kurva Anda dengan kurva model
|
|
66
|
+
ber-segmentasi sub-kata; keduanya mengukur unit yang berbeda. Perilaku awal seperti
|
|
67
|
+
pengulangan pada teks yang digenerasi adalah fase belajar substrat, bukan bug decoding.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Kurikulum Data NINMENI — Panduan Ringkas
|
|
2
|
+
|
|
3
|
+
Dua jalur data, dua peran yang berbeda dan tidak boleh dicampur:
|
|
4
|
+
|
|
5
|
+
## 1. Pretraining — membentuk PEMAHAMAN
|
|
6
|
+
- Isi: teks aktual (prosa komunikasi nyata) berbahasa Indonesia — artikel, dokumentasi,
|
|
7
|
+
narasi, kode dengan penjelasan. Format: JSONL `{"teks": "..."}` (lihat
|
|
8
|
+
`examples/curriculum/pretraining_contoh.jsonl`).
|
|
9
|
+
- Prinsip: substrat belajar dari BAHASA HIDUP. Format meta-linguistik (tabel kamus,
|
|
10
|
+
daftar lema, anotasi kelas kata) bukan corpus — kamus adalah alat kurasi, bukan data.
|
|
11
|
+
- Setiap sumber wajib berlisensi jelas dan tercatat (URL + lisensi + hash) di manifest
|
|
12
|
+
Anda sendiri. Jangan gunakan data yang tidak boleh Anda gunakan.
|
|
13
|
+
- Konten pengetahuan dunia (fakta, statistik, budaya) masuk ke jalur INI — bukan ke SFT.
|
|
14
|
+
|
|
15
|
+
## 2. SFT — membentuk PROTOKOL DIALOG ("mulut")
|
|
16
|
+
- Isi: contoh percakapan/tugas dalam format turns (lihat `examples/curriculum/sft_contoh.jsonl`).
|
|
17
|
+
- Peran: mengajarkan BENTUK berinteraksi (format jawaban, protokol tool, gaya) — bukan
|
|
18
|
+
menjejalkan fakta. Fakta yang hanya ada di SFT cenderung rapuh.
|
|
19
|
+
- Penalaran bertahap diajarkan sebagai LINTASAN: enumerasi langkah searah penulisan,
|
|
20
|
+
jawaban = kelanjutan alami dari langkahnya (lihat contoh `reason`).
|
|
21
|
+
|
|
22
|
+
## Prinsip lintas-jalur
|
|
23
|
+
- 1 karakter = 1 ID: registry karakter statis (`registry/nmu_v1.json`) berlaku untuk
|
|
24
|
+
SEMUA data. Teks yang memuat karakter di luar registry tidak dipaksa masuk — catat
|
|
25
|
+
dan putuskan secara sadar (normalisasi terdokumentasi, atau buang utuh).
|
|
26
|
+
- Tanpa UNK: kegagalan encode = masalah validasi data, bukan sesuatu yang ditambal.
|
|
27
|
+
- Evaluasi model native dibaca dengan kacamata native: model karakter-level punya
|
|
28
|
+
ritme belajar sendiri; jangan menilai dengan ekspektasi paradigma lain.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
{"teks": "Danau Toba terletak di Provinsi Sumatera Utara. Danau vulkanik ini terbentuk dari letusan purba dan menjadi rumah bagi Pulau Samosir di tengahnya."}
|
|
2
|
+
{"teks": "Fotosintesis adalah proses tumbuhan mengubah cahaya matahari, air, dan karbon dioksida menjadi energi. Prosesnya berlangsung di daun, tepatnya di dalam kloroplas."}
|
|
3
|
+
{"teks": "def hitung_keliling_lingkaran(jari_jari):\n import math\n return 2 * math.pi * jari_jari\n\n# Keliling lingkaran dihitung dari jari-jarinya."}
|
|
4
|
+
{"teks": "Harga beras di pasar tradisional pekan ini berkisar antara Rp13.000 sampai Rp15.000 per kilogram, bergantung pada kualitas dan daerah."}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
{"cat": "qa", "turns": [{"role": "user", "content": "Apa ibukota Provinsi Jawa Tengah?"}, {"role": "assistant", "content": "Semarang."}]}
|
|
2
|
+
{"cat": "multi_qa", "turns": [{"role": "user", "content": "Sungai terpanjang di Indonesia apa?"}, {"role": "assistant", "content": "Sungai Kapuas di Kalimantan Barat."}, {"role": "user", "content": "Berapa kira-kira panjangnya?"}, {"role": "assistant", "content": "Sekitar 1.143 kilometer."}]}
|
|
3
|
+
{"cat": "reason", "turns": [{"role": "user", "content": "Jika hari ini Senin, tiga hari lagi hari apa?"}, {"role": "assistant", "content": "Langkah: Senin + 3 hari. Urut: Selasa, Rabu, Kamis. Jadi Kamis."}]}
|
|
4
|
+
{"cat": "task", "turns": [{"role": "user", "content": "Sebutkan 3 pulau besar di Indonesia."}, {"role": "assistant", "content": "1. Sumatera 2. Kalimantan 3. Papua"}]}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""reference_model.py — MODEL REFERENSI untuk pipeline NINMENI.
|
|
2
|
+
|
|
3
|
+
PENTING: ini BUKAN arsitektur Veyra. Ini decoder-only transformer karakter-level
|
|
4
|
+
yang sengaja dibuat polos dan mudah dibaca, dengan satu tujuan: pipeline di repo
|
|
5
|
+
ini bisa dijalankan ujung-ke-ujung, dan Anda punya titik colok yang jelas untuk
|
|
6
|
+
arsitektur Anda sendiri.
|
|
7
|
+
|
|
8
|
+
Kontrak antarmuka yang dituntut trainer (lihat docs/antarmuka-model.md):
|
|
9
|
+
- Config : dataclass; field mencakup kunci `model:` di configs/*.yaml
|
|
10
|
+
+ ukuran_ruang + pad_id (diisi trainer dari registry).
|
|
11
|
+
- Model : __init__(cfg); menyimpan `self.cfg`;
|
|
12
|
+
forward(x[B,T] long) -> logits [B, T, ukuran_ruang];
|
|
13
|
+
loss(x[B,T]) -> scalar CE SHIFTED (predict karakter berikutnya).
|
|
14
|
+
- count_params(model) -> int.
|
|
15
|
+
|
|
16
|
+
Prinsip native yang dijaga di sini:
|
|
17
|
+
- Input = deretan ID karakter (1 karakter = 1 ID, registry-driven). Tidak ada
|
|
18
|
+
segmentasi apa pun sebelum model.
|
|
19
|
+
- Loss WAJIB shifted: logits[:, :-1] vs target x[:, 1:]. Loss tanpa shift =
|
|
20
|
+
model belajar menyalin, bukan memprediksi.
|
|
21
|
+
- PAD tidak dilatih dan tidak dilihat attention.
|
|
22
|
+
"""
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import math
|
|
26
|
+
from dataclasses import dataclass
|
|
27
|
+
|
|
28
|
+
import torch
|
|
29
|
+
import torch.nn as nn
|
|
30
|
+
import torch.nn.functional as F
|
|
31
|
+
from torch.utils.checkpoint import checkpoint
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class ReferenceConfig:
|
|
36
|
+
ukuran_ruang: int = 4450 # ukuran ruang karakter registry (jumlah ID)
|
|
37
|
+
pad_id: int = 0
|
|
38
|
+
d_model: int = 768
|
|
39
|
+
n_layers: int = 12
|
|
40
|
+
n_heads: int = 12
|
|
41
|
+
n_kv_heads: int = 4 # diterima demi kompatibilitas config; referensi memakai MHA penuh
|
|
42
|
+
mlp_ratio: float = 4.0
|
|
43
|
+
rope_theta: float = 10000.0
|
|
44
|
+
grad_checkpoint: bool = False
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _rope(q, k, theta):
|
|
48
|
+
# Penyandian posisi rotari (RoPE) sederhana (separuh-dimensi berpasangan).
|
|
49
|
+
B, H, T, D = q.shape
|
|
50
|
+
half = D // 2
|
|
51
|
+
freqs = theta ** (-torch.arange(0, half, device=q.device, dtype=torch.float32) / half)
|
|
52
|
+
pos = torch.arange(T, device=q.device, dtype=torch.float32)
|
|
53
|
+
ang = torch.outer(pos, freqs) # [T, half]
|
|
54
|
+
cos, sin = ang.cos()[None, None], ang.sin()[None, None]
|
|
55
|
+
|
|
56
|
+
def rot(x):
|
|
57
|
+
x1, x2 = x[..., :half], x[..., half:]
|
|
58
|
+
return torch.cat([x1 * cos - x2 * sin, x1 * sin + x2 * cos], dim=-1)
|
|
59
|
+
|
|
60
|
+
return rot(q), rot(k)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class _Block(nn.Module):
|
|
64
|
+
def __init__(self, cfg: ReferenceConfig):
|
|
65
|
+
super().__init__()
|
|
66
|
+
self.cfg = cfg
|
|
67
|
+
self.norm1 = nn.RMSNorm(cfg.d_model)
|
|
68
|
+
self.norm2 = nn.RMSNorm(cfg.d_model)
|
|
69
|
+
self.qkv = nn.Linear(cfg.d_model, 3 * cfg.d_model, bias=False)
|
|
70
|
+
self.proj = nn.Linear(cfg.d_model, cfg.d_model, bias=False)
|
|
71
|
+
hidden = int(cfg.d_model * cfg.mlp_ratio)
|
|
72
|
+
self.mlp = nn.Sequential(
|
|
73
|
+
nn.Linear(cfg.d_model, hidden, bias=False),
|
|
74
|
+
nn.GELU(),
|
|
75
|
+
nn.Linear(hidden, cfg.d_model, bias=False),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
def forward(self, x, pad_mask=None):
|
|
79
|
+
B, T, C = x.shape
|
|
80
|
+
H = self.cfg.n_heads
|
|
81
|
+
q, k, v = self.qkv(self.norm1(x)).chunk(3, dim=-1)
|
|
82
|
+
q = q.view(B, T, H, C // H).transpose(1, 2)
|
|
83
|
+
k = k.view(B, T, H, C // H).transpose(1, 2)
|
|
84
|
+
v = v.view(B, T, H, C // H).transpose(1, 2)
|
|
85
|
+
q, k = _rope(q, k, self.cfg.rope_theta)
|
|
86
|
+
attn_mask = None
|
|
87
|
+
if pad_mask is not None:
|
|
88
|
+
# PAD tidak boleh dilihat sebagai key oleh posisi mana pun.
|
|
89
|
+
attn_mask = pad_mask[:, None, None, :].expand(B, 1, T, T)
|
|
90
|
+
out = F.scaled_dot_product_attention(q, k, v, attn_mask=attn_mask, is_causal=True)
|
|
91
|
+
x = x + self.proj(out.transpose(1, 2).reshape(B, T, C))
|
|
92
|
+
x = x + self.mlp(self.norm2(x))
|
|
93
|
+
return x
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class ReferenceNativeModel(nn.Module):
|
|
97
|
+
def __init__(self, cfg: ReferenceConfig):
|
|
98
|
+
super().__init__()
|
|
99
|
+
self.cfg = cfg
|
|
100
|
+
self.emb = nn.Embedding(cfg.ukuran_ruang, cfg.d_model, padding_idx=cfg.pad_id)
|
|
101
|
+
self.blocks = nn.ModuleList(_Block(cfg) for _ in range(cfg.n_layers))
|
|
102
|
+
self.norm_f = nn.RMSNorm(cfg.d_model)
|
|
103
|
+
self.head = nn.Linear(cfg.d_model, cfg.ukuran_ruang, bias=False)
|
|
104
|
+
self.head.weight = self.emb.weight # tied
|
|
105
|
+
# Init kecil (std 0.02) — tanpa ini logits awal membesar dan CE awal
|
|
106
|
+
# jauh di atas ln(ukuran ruang). Uji waras: loss step-0 harus ~ ln(ukuran_ruang).
|
|
107
|
+
self.apply(self._init)
|
|
108
|
+
|
|
109
|
+
@staticmethod
|
|
110
|
+
def _init(m):
|
|
111
|
+
if isinstance(m, (nn.Linear, nn.Embedding)):
|
|
112
|
+
nn.init.normal_(m.weight, mean=0.0, std=0.02)
|
|
113
|
+
|
|
114
|
+
def forward(self, x):
|
|
115
|
+
pad_mask = None
|
|
116
|
+
if (x == self.cfg.pad_id).any():
|
|
117
|
+
pad_mask = x != self.cfg.pad_id # True = boleh dilihat
|
|
118
|
+
h = self.emb(x)
|
|
119
|
+
for blk in self.blocks:
|
|
120
|
+
if self.cfg.grad_checkpoint and self.training:
|
|
121
|
+
h = checkpoint(blk, h, pad_mask, use_reentrant=False)
|
|
122
|
+
else:
|
|
123
|
+
h = blk(h, pad_mask)
|
|
124
|
+
return self.head(self.norm_f(h))
|
|
125
|
+
|
|
126
|
+
def loss(self, x):
|
|
127
|
+
"""CE SHIFTED — objective pretraining native (predict karakter berikutnya)."""
|
|
128
|
+
logits = self.forward(x)
|
|
129
|
+
return F.cross_entropy(
|
|
130
|
+
logits[:, :-1, :].reshape(-1, self.cfg.ukuran_ruang),
|
|
131
|
+
x[:, 1:].reshape(-1),
|
|
132
|
+
ignore_index=self.cfg.pad_id,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def count_params(model) -> int:
|
|
137
|
+
return sum(p.numel() for p in model.parameters())
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# Alias kompatibilitas — trainer mengimpor nama-nama ini. Saat Anda menulis
|
|
141
|
+
# arsitektur sendiri, ekspor nama yang sama dari modul Anda dan arahkan import
|
|
142
|
+
# di training/train_unified_native.py ke sana.
|
|
143
|
+
VeyraNativeConfig = ReferenceConfig
|
|
144
|
+
VeyraNativeModel = ReferenceNativeModel
|