@mailwoman/mtf 0.0.0-stage → 10.8.0
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.
- package/README.md +221 -2
- package/THIRD_PARTY_NOTICES.md +31 -0
- package/crates/mtf-channels/tests/fixtures/README.md +13 -0
- package/crates/mtf-sampler/tests/fixtures/README.md +120 -0
- package/lib/code-units.ts +45 -0
- package/lib/index.ts +266 -0
- package/out/code-units.d.ts +24 -0
- package/out/code-units.d.ts.map +1 -0
- package/out/code-units.js +36 -0
- package/out/code-units.js.map +1 -0
- package/out/index.d.ts +128 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +171 -0
- package/out/index.js.map +1 -0
- package/out/tools/build-wasm.run.d.ts +14 -0
- package/out/tools/build-wasm.run.d.ts.map +1 -0
- package/out/tools/build-wasm.run.js +42 -0
- package/out/tools/build-wasm.run.js.map +1 -0
- package/out/tools/sampler/native.d.ts +314 -0
- package/out/tools/sampler/native.d.ts.map +1 -0
- package/out/tools/sampler/native.js +114 -0
- package/out/tools/sampler/native.js.map +1 -0
- package/out/tools/tokenizer/binary.d.ts +38 -0
- package/out/tools/tokenizer/binary.d.ts.map +1 -0
- package/out/tools/tokenizer/binary.js +94 -0
- package/out/tools/tokenizer/binary.js.map +1 -0
- package/out/tools/tokenizer/byte-fallback.d.ts +39 -0
- package/out/tools/tokenizer/byte-fallback.d.ts.map +1 -0
- package/out/tools/tokenizer/byte-fallback.js +49 -0
- package/out/tools/tokenizer/byte-fallback.js.map +1 -0
- package/out/tools/tokenizer/model.d.ts +70 -0
- package/out/tools/tokenizer/model.d.ts.map +1 -0
- package/out/tools/tokenizer/model.js +56 -0
- package/out/tools/tokenizer/model.js.map +1 -0
- package/out/tools/tokenizer/prune.d.ts +69 -0
- package/out/tools/tokenizer/prune.d.ts.map +1 -0
- package/out/tools/tokenizer/prune.js +126 -0
- package/out/tools/tokenizer/prune.js.map +1 -0
- package/out/tools/tokenizer/prune.run.d.ts +16 -0
- package/out/tools/tokenizer/prune.run.d.ts.map +1 -0
- package/out/tools/tokenizer/prune.run.js +34 -0
- package/out/tools/tokenizer/prune.run.js.map +1 -0
- package/out/tools/tokenizer/sentencepiece.d.ts +63 -0
- package/out/tools/tokenizer/sentencepiece.d.ts.map +1 -0
- package/out/tools/tokenizer/sentencepiece.js +90 -0
- package/out/tools/tokenizer/sentencepiece.js.map +1 -0
- package/out/tools/tokenizer/splice.d.ts +117 -0
- package/out/tools/tokenizer/splice.d.ts.map +1 -0
- package/out/tools/tokenizer/splice.js +398 -0
- package/out/tools/tokenizer/splice.js.map +1 -0
- package/out/tools/tokenizer/splice.run.d.ts +29 -0
- package/out/tools/tokenizer/splice.run.d.ts.map +1 -0
- package/out/tools/tokenizer/splice.run.js +114 -0
- package/out/tools/tokenizer/splice.run.js.map +1 -0
- package/out/tools/tokenizer/symbols.d.ts +42 -0
- package/out/tools/tokenizer/symbols.d.ts.map +1 -0
- package/out/tools/tokenizer/symbols.js +113 -0
- package/out/tools/tokenizer/symbols.js.map +1 -0
- package/out/tools/tokenizer/train/text.run.d.ts +16 -0
- package/out/tools/tokenizer/train/text.run.d.ts.map +1 -0
- package/out/tools/tokenizer/train/text.run.js +67 -0
- package/out/tools/tokenizer/train/text.run.js.map +1 -0
- package/out/tools/tokenizer/train.d.ts +113 -0
- package/out/tools/tokenizer/train.d.ts.map +1 -0
- package/out/tools/tokenizer/train.js +162 -0
- package/out/tools/tokenizer/train.js.map +1 -0
- package/out/tools/tokenizer/train.run.d.ts +24 -0
- package/out/tools/tokenizer/train.run.d.ts.map +1 -0
- package/out/tools/tokenizer/train.run.js +131 -0
- package/out/tools/tokenizer/train.run.js.map +1 -0
- package/out/tools/tokenizer/utilization.run.d.ts +17 -0
- package/out/tools/tokenizer/utilization.run.d.ts.map +1 -0
- package/out/tools/tokenizer/utilization.run.js +80 -0
- package/out/tools/tokenizer/utilization.run.js.map +1 -0
- package/out/tools/tokenizer/verify.d.ts +94 -0
- package/out/tools/tokenizer/verify.d.ts.map +1 -0
- package/out/tools/tokenizer/verify.js +193 -0
- package/out/tools/tokenizer/verify.js.map +1 -0
- package/out/tools/tokenizer/verify.run.d.ts +22 -0
- package/out/tools/tokenizer/verify.run.d.ts.map +1 -0
- package/out/tools/tokenizer/verify.run.js +71 -0
- package/out/tools/tokenizer/verify.run.js.map +1 -0
- package/package.json +107 -3
- package/third-party/darts-clone/LICENSE +10 -0
- package/third-party/sentencepiece/LICENSE +202 -0
- package/tools/build-wasm.run.ts +48 -0
- package/tools/sampler/native.ts +433 -0
- package/tools/tokenizer/binary.ts +118 -0
- package/tools/tokenizer/byte-fallback.ts +80 -0
- package/tools/tokenizer/model.ts +110 -0
- package/tools/tokenizer/prune.run.ts +37 -0
- package/tools/tokenizer/prune.ts +195 -0
- package/tools/tokenizer/sentencepiece.ts +142 -0
- package/tools/tokenizer/splice.run.ts +141 -0
- package/tools/tokenizer/splice.ts +592 -0
- package/tools/tokenizer/symbols.ts +119 -0
- package/tools/tokenizer/train/text.run.ts +80 -0
- package/tools/tokenizer/train.run.ts +151 -0
- package/tools/tokenizer/train.ts +266 -0
- package/tools/tokenizer/utilization.run.ts +96 -0
- package/tools/tokenizer/verify.run.ts +77 -0
- package/tools/tokenizer/verify.ts +313 -0
- package/wasm/mtf.wasm +0 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The two checks a pruned tokenizer and model pass before release.
|
|
7
|
+
*
|
|
8
|
+
* B1, segmentation identity: the original and pruned tokenizers produce the same piece sequence, modulo the id
|
|
9
|
+
* renumbering, on every evaluation text and on a random sample of the training rows.
|
|
10
|
+
*
|
|
11
|
+
* B2, logit identity: the original and pruned int8 models answer the evaluation inputs with the same output bits.
|
|
12
|
+
* The graphs differ only in the embedding table and the kept rows are the same bytes, so any difference is a defect
|
|
13
|
+
* of the surgery. Every channel input is fed zeros, because the identity must hold for any channel values. The
|
|
14
|
+
* release battery covers realistic inputs.
|
|
15
|
+
*/
|
|
16
|
+
import { readLocalJSONFile } from "@mailwoman/core/fs/readers";
|
|
17
|
+
import { temporaryDirectory } from "@mailwoman/core/fs/temporary";
|
|
18
|
+
import { writeLocalJSONFile, writeLocalTextFile } from "@mailwoman/core/fs/writers";
|
|
19
|
+
import { prettyJSON, stringifyJSON } from "@mailwoman/core/json";
|
|
20
|
+
import { runMTFTokenizer } from "./binary.js";
|
|
21
|
+
import { loadEncoder } from "./model.js";
|
|
22
|
+
/**
|
|
23
|
+
* The number of differing texts each check prints in full.
|
|
24
|
+
* The rest are only counted.
|
|
25
|
+
*/
|
|
26
|
+
const SEGMENTATION_DIFFERENCES_SHOWN = 5;
|
|
27
|
+
const LOGIT_DIFFERENCES_SHOWN = 3;
|
|
28
|
+
/**
|
|
29
|
+
* B1: the number of `texts` the two tokenizers segment differently, modulo the renumbering.
|
|
30
|
+
*
|
|
31
|
+
* An id that maps to -1 counts as a difference on its own: the pruned vocabulary
|
|
32
|
+
* dropped a piece the text needs.
|
|
33
|
+
*/
|
|
34
|
+
export function checkSegmentationIdentity(original, pruned, oldToNew, texts, label) {
|
|
35
|
+
let differing = 0;
|
|
36
|
+
for (const text of texts) {
|
|
37
|
+
const before = original.encode(text);
|
|
38
|
+
const after = pruned.encode(text);
|
|
39
|
+
const mapped = before.ids.map((id) => oldToNew[id] ?? -1);
|
|
40
|
+
if (mapped.includes(-1) || mapped.length !== after.ids.length || mapped.some((id, i) => id !== after.ids[i])) {
|
|
41
|
+
differing++;
|
|
42
|
+
if (differing <= SEGMENTATION_DIFFERENCES_SHOWN) {
|
|
43
|
+
console.info(`[B1 DIFF] ${label}: ${stringifyJSON(text)}`);
|
|
44
|
+
console.info(` orig : ${stringifyJSON(before.pieces)}`);
|
|
45
|
+
console.info(` pruned: ${stringifyJSON(after.pieces)}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
console.info(`[B1] ${label}: ${texts.length.toLocaleString("en-US")} texts, ${differing} diffs`);
|
|
50
|
+
return differing;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* One input's feed for `ids`: the ids for `input_ids`, ones for `attention_mask`,
|
|
54
|
+
* zeros for every other input.
|
|
55
|
+
*/
|
|
56
|
+
export function feedsFor(metas, ids) {
|
|
57
|
+
const feeds = {};
|
|
58
|
+
for (const meta of metas) {
|
|
59
|
+
const type = meta.type.includes("int64") ? "int64" : "float32";
|
|
60
|
+
const dims = meta.shape.map((dim) => {
|
|
61
|
+
if (dim === "batch")
|
|
62
|
+
return 1;
|
|
63
|
+
if (dim === "sequence")
|
|
64
|
+
return ids.length;
|
|
65
|
+
const size = Number(dim);
|
|
66
|
+
if (!Number.isInteger(size))
|
|
67
|
+
throw new Error(`input ${meta.name} has the unresolved dimension ${dim}`);
|
|
68
|
+
return size;
|
|
69
|
+
});
|
|
70
|
+
const size = dims.reduce((product, d) => product * d, 1);
|
|
71
|
+
let data;
|
|
72
|
+
if (meta.name === "input_ids") {
|
|
73
|
+
data = BigInt64Array.from(ids, (id) => BigInt(id));
|
|
74
|
+
}
|
|
75
|
+
else if (type === "int64") {
|
|
76
|
+
data = new BigInt64Array(size).fill(meta.name === "attention_mask" ? 1n : 0n);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
data = new Float32Array(size).fill(meta.name === "attention_mask" ? 1 : 0);
|
|
80
|
+
}
|
|
81
|
+
feeds[meta.name] = { type, data, dims };
|
|
82
|
+
}
|
|
83
|
+
return feeds;
|
|
84
|
+
}
|
|
85
|
+
function bytesOf(values) {
|
|
86
|
+
return Buffer.from(values.buffer, values.byteOffset, values.byteLength);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* B2: the number of `texts` the two models answer differently, bit for bit.
|
|
90
|
+
*
|
|
91
|
+
* An unmapped id is refused, because the comparison would score a graph against inputs it cannot represent.
|
|
92
|
+
*/
|
|
93
|
+
export async function checkLogitParity(original, oldToNew, originalSession, prunedSession, texts) {
|
|
94
|
+
let differing = 0;
|
|
95
|
+
for (const text of texts) {
|
|
96
|
+
const ids = original.encode(text).ids;
|
|
97
|
+
const mapped = ids.map((id) => oldToNew[id] ?? -1);
|
|
98
|
+
if (mapped.includes(-1))
|
|
99
|
+
throw new Error(`unmapped id in B2 input: ${stringifyJSON(text)}`);
|
|
100
|
+
const before = await originalSession.run(feedsFor(originalSession.inputs, ids));
|
|
101
|
+
const after = await prunedSession.run(feedsFor(prunedSession.inputs, mapped));
|
|
102
|
+
for (let k = 0; k < before.length; k++) {
|
|
103
|
+
if (!bytesOf(before[k]).equals(bytesOf(after[k]))) {
|
|
104
|
+
differing++;
|
|
105
|
+
if (differing <= LOGIT_DIFFERENCES_SHOWN) {
|
|
106
|
+
let largest = 0;
|
|
107
|
+
before[k].forEach((v, i) => (largest = Math.max(largest, Math.abs(v - after[k][i]))));
|
|
108
|
+
console.info(`[B2 DIFF] ${stringifyJSON(text)}: max |Δ| ${largest}`);
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
console.info(`[B2] ${texts.length} inputs, ${differing} non-bit-equal`);
|
|
115
|
+
return differing;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* An onnxruntime-node session over `path`, with four intra-op threads on the CPU.
|
|
119
|
+
*/
|
|
120
|
+
async function openLogitSession(path) {
|
|
121
|
+
const ort = await import("onnxruntime-node");
|
|
122
|
+
const session = await ort.InferenceSession.create(path, {
|
|
123
|
+
intraOpNumThreads: 4,
|
|
124
|
+
executionProviders: ["cpu"],
|
|
125
|
+
});
|
|
126
|
+
const inputs = session.inputMetadata.flatMap((meta) => meta.isTensor ? [{ name: meta.name, type: meta.type, shape: meta.shape }] : []);
|
|
127
|
+
return {
|
|
128
|
+
inputs,
|
|
129
|
+
async run(feeds) {
|
|
130
|
+
const tensors = Object.fromEntries(Object.entries(feeds).map(([name, feed]) => [name, new ort.Tensor(feed.type, feed.data, feed.dims)]));
|
|
131
|
+
const outputs = await session.run(tensors);
|
|
132
|
+
return session.outputNames.map((name) => outputs[name].data);
|
|
133
|
+
},
|
|
134
|
+
[Symbol.asyncDispose]: () => session.release(),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Run B1 and B2 over a pruned directory and write `verify-report.json` into it.
|
|
139
|
+
*/
|
|
140
|
+
export async function verifyPrune(options) {
|
|
141
|
+
const seed = options.seed ?? 42;
|
|
142
|
+
const { old_to_new: oldToNew } = await readLocalJSONFile(`${options.prunedDirectory}/id-map.json`);
|
|
143
|
+
const { texts: evalTexts } = await readLocalJSONFile(options.evalTexts);
|
|
144
|
+
await using scratch = await temporaryDirectory("mtf-verify-");
|
|
145
|
+
const listed = await runMTFTokenizer(["manifest-train-files", "--manifest", options.manifest]);
|
|
146
|
+
const [from, to] = options.remap;
|
|
147
|
+
const files = listed.map((path) => (path.startsWith(from) ? to + path.slice(from.length) : path));
|
|
148
|
+
const filesPath = scratch.path("files.json").toString();
|
|
149
|
+
const rowsPath = scratch.path("rows.json").toString();
|
|
150
|
+
await writeLocalJSONFile(files, filesPath);
|
|
151
|
+
await runMTFTokenizer([
|
|
152
|
+
"sample-rows",
|
|
153
|
+
"--files",
|
|
154
|
+
filesPath,
|
|
155
|
+
"--rows",
|
|
156
|
+
String(options.sampleRows ?? 1_000_000),
|
|
157
|
+
"--seed",
|
|
158
|
+
String(seed),
|
|
159
|
+
"--out",
|
|
160
|
+
rowsPath,
|
|
161
|
+
]);
|
|
162
|
+
const trainSample = await readLocalJSONFile(rowsPath);
|
|
163
|
+
using original = await loadEncoder(options.originalTokenizer);
|
|
164
|
+
using pruned = await loadEncoder(`${options.prunedDirectory}/tokenizer.model`);
|
|
165
|
+
let b1 = checkSegmentationIdentity(original, pruned, oldToNew, evalTexts, "eval-surface");
|
|
166
|
+
b1 += checkSegmentationIdentity(original, pruned, oldToNew, trainSample, "train-sample");
|
|
167
|
+
const picked = await runMTFTokenizer([
|
|
168
|
+
"sample-indices",
|
|
169
|
+
"--population",
|
|
170
|
+
String(evalTexts.length),
|
|
171
|
+
"--count",
|
|
172
|
+
String(Math.min(options.logitInputs ?? 256, evalTexts.length)),
|
|
173
|
+
"--seed",
|
|
174
|
+
String(seed),
|
|
175
|
+
]);
|
|
176
|
+
const logitTexts = picked.map((i) => evalTexts[i]);
|
|
177
|
+
await using originalSession = await openLogitSession(options.originalONNX);
|
|
178
|
+
await using prunedSession = await openLogitSession(`${options.prunedDirectory}/model.onnx`);
|
|
179
|
+
const b2 = await checkLogitParity(original, oldToNew, originalSession, prunedSession, logitTexts);
|
|
180
|
+
const verdict = b1 === 0 && b2 === 0 ? "PASS" : "FAIL";
|
|
181
|
+
console.info(`VERDICT: ${verdict} (B1 diffs ${b1}, B2 diffs ${b2})`);
|
|
182
|
+
const report = {
|
|
183
|
+
b1_eval_texts: evalTexts.length,
|
|
184
|
+
b1_train_sample: trainSample.length,
|
|
185
|
+
b1_diffs: b1,
|
|
186
|
+
b2_inputs: logitTexts.length,
|
|
187
|
+
b2_diffs: b2,
|
|
188
|
+
verdict,
|
|
189
|
+
};
|
|
190
|
+
await writeLocalTextFile(prettyJSON(report, true, 1), `${options.prunedDirectory}/verify-report.json`);
|
|
191
|
+
return report;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../../tools/tokenizer/verify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACnF,OAAO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EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAA;IAEtD,OAAO,CAAC,IAAI,CAAC,YAAY,OAAO,cAAc,EAAE,cAAc,EAAE,GAAG,CAAC,CAAA;IAEpE,MAAM,MAAM,GAAiB;QAC5B,aAAa,EAAE,SAAS,CAAC,MAAM;QAC/B,eAAe,EAAE,WAAW,CAAC,MAAM;QACnC,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,UAAU,CAAC,MAAM;QAC5B,QAAQ,EAAE,EAAE;QACZ,OAAO;KACP,CAAA;IAED,MAAM,kBAAkB,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,eAAe,qBAAqB,CAAC,CAAA;IAEtG,OAAO,MAAM,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Check a tokenizer.
|
|
7
|
+
*
|
|
8
|
+
* `byte-fallback` encodes a held-out fixture (JSONL with `raw`, `text` or `input`, or plain text) and prints the
|
|
9
|
+
* byte-fallback rate overall and per script.
|
|
10
|
+
*
|
|
11
|
+
* `prune` runs the two release checks of a pruned tokenizer and model, segmentation identity (B1) and bit-equal
|
|
12
|
+
* logits (B2), writes `verify-report.json` into the pruned directory, and exits non-zero unless both pass.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
*
|
|
16
|
+
* node packages/mtf/tools/tokenizer/verify.run.ts byte-fallback --tokenizer <model> --fixture <jsonl>
|
|
17
|
+
* node packages/mtf/tools/tokenizer/verify.run.ts prune --orig-tokenizer <model> --orig-onnx <onnx>
|
|
18
|
+
* --pruned-dir <dir> --manifest <MANIFEST.json> --eval-texts <json> [--sample-rows 1000000]
|
|
19
|
+
* [--logit-inputs 256] [--seed 42] [--data-root-remap <from>:<to>]
|
|
20
|
+
*/
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=verify.run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.run.d.ts","sourceRoot":"","sources":["../../../tools/tokenizer/verify.run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Check a tokenizer.
|
|
7
|
+
*
|
|
8
|
+
* `byte-fallback` encodes a held-out fixture (JSONL with `raw`, `text` or `input`, or plain text) and prints the
|
|
9
|
+
* byte-fallback rate overall and per script.
|
|
10
|
+
*
|
|
11
|
+
* `prune` runs the two release checks of a pruned tokenizer and model, segmentation identity (B1) and bit-equal
|
|
12
|
+
* logits (B2), writes `verify-report.json` into the pruned directory, and exits non-zero unless both pass.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
*
|
|
16
|
+
* node packages/mtf/tools/tokenizer/verify.run.ts byte-fallback --tokenizer <model> --fixture <jsonl>
|
|
17
|
+
* node packages/mtf/tools/tokenizer/verify.run.ts prune --orig-tokenizer <model> --orig-onnx <onnx>
|
|
18
|
+
* --pruned-dir <dir> --manifest <MANIFEST.json> --eval-texts <json> [--sample-rows 1000000]
|
|
19
|
+
* [--logit-inputs 256] [--seed 42] [--data-root-remap <from>:<to>]
|
|
20
|
+
*/
|
|
21
|
+
import { dataRootPath } from "@mailwoman/core/data-root";
|
|
22
|
+
import { prettyJSON } from "@mailwoman/core/json";
|
|
23
|
+
import { parseArguments, requiredArgument } from "@mailwoman/core/scripting/arguments";
|
|
24
|
+
import { resolvePath } from "path-ts";
|
|
25
|
+
import { measureByteFallback, readFixtureLines } from "./byte-fallback.js";
|
|
26
|
+
import { verifyPrune } from "./verify.js";
|
|
27
|
+
const { values, positionals } = parseArguments({
|
|
28
|
+
allowPositionals: true,
|
|
29
|
+
options: {
|
|
30
|
+
tokenizer: { type: "string" },
|
|
31
|
+
fixture: { type: "string" },
|
|
32
|
+
"orig-tokenizer": { type: "string" },
|
|
33
|
+
"orig-onnx": { type: "string" },
|
|
34
|
+
"pruned-dir": { type: "string" },
|
|
35
|
+
manifest: { type: "string" },
|
|
36
|
+
"eval-texts": { type: "string" },
|
|
37
|
+
"sample-rows": { type: "string", default: "1000000" },
|
|
38
|
+
"logit-inputs": { type: "string", default: "256" },
|
|
39
|
+
seed: { type: "string", default: "42" },
|
|
40
|
+
"data-root-remap": { type: "string" },
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const command = positionals[0];
|
|
44
|
+
if (command === "byte-fallback") {
|
|
45
|
+
const tokenizer = resolvePath(requiredArgument(command, "tokenizer", values.tokenizer));
|
|
46
|
+
const fixture = resolvePath(requiredArgument(command, "fixture", values.fixture));
|
|
47
|
+
console.log(prettyJSON(await measureByteFallback(tokenizer, await readFixtureLines(fixture)), false, 2));
|
|
48
|
+
}
|
|
49
|
+
else if (command === "prune") {
|
|
50
|
+
const remap = values["data-root-remap"] ?? `/data:${dataRootPath()}`;
|
|
51
|
+
const at = remap.indexOf(":");
|
|
52
|
+
const report = await verifyPrune({
|
|
53
|
+
originalTokenizer: resolvePath(requiredArgument(command, "orig-tokenizer", values["orig-tokenizer"])),
|
|
54
|
+
originalONNX: resolvePath(requiredArgument(command, "orig-onnx", values["orig-onnx"])),
|
|
55
|
+
prunedDirectory: resolvePath(requiredArgument(command, "pruned-dir", values["pruned-dir"])),
|
|
56
|
+
manifest: resolvePath(requiredArgument(command, "manifest", values.manifest)),
|
|
57
|
+
evalTexts: resolvePath(requiredArgument(command, "eval-texts", values["eval-texts"])),
|
|
58
|
+
sampleRows: Number(values["sample-rows"]),
|
|
59
|
+
logitInputs: Number(values["logit-inputs"]),
|
|
60
|
+
seed: Number(values.seed),
|
|
61
|
+
remap: [remap.slice(0, at), remap.slice(at + 1)],
|
|
62
|
+
});
|
|
63
|
+
if (report.verdict !== "PASS") {
|
|
64
|
+
process.exitCode = 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.error("usage: verify.run.ts byte-fallback|prune [options]");
|
|
69
|
+
process.exitCode = 2;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=verify.run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.run.js","sourceRoot":"","sources":["../../../tools/tokenizer/verify.run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAA;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,cAAc,CAAC;IAC9C,gBAAgB,EAAE,IAAI;IACtB,OAAO,EAAE;QACR,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC7B,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC3B,gBAAgB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACpC,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC/B,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAChC,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC5B,YAAY,E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AAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;QACtF,eAAe,EAAE,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;QAC3F,QAAQ,EAAE,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC7E,SAAS,EAAE,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;QACrF,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QACzC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QAC3C,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QACzB,KAAK,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;KAChD,CAAC,CAAA;IAEF,IAAI,MAAM,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;QAC/B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;IACrB,CAAC;AACF,CAAC;KAAM,CAAC;IACP,OAAO,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAA;IAEnE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;AACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,110 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mailwoman/mtf",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "10.8.0",
|
|
4
|
+
"description": "Multilingual Token Framework: Mailwoman's subword tokenizer, a Rust core compiled to WASM with a TypeScript loader. It reproduces SentencePiece v0.2.2's pieces and offsets on the shipped unigram model and is the tokenizer runtime for @mailwoman/neural.",
|
|
5
|
+
"license": "AGPL-3.0-only OR LicenseRef-Commercial",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/sister-software/mailwoman.git",
|
|
9
|
+
"directory": "packages/mtf"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"out/**/*.js",
|
|
13
|
+
"out/**/*.js.map",
|
|
14
|
+
"out/**/*.d.ts",
|
|
15
|
+
"out/**/*.d.ts.map",
|
|
16
|
+
"lib/**/*.ts",
|
|
17
|
+
"tools/**/*.ts",
|
|
18
|
+
"wasm/mtf.wasm",
|
|
19
|
+
"README.md",
|
|
20
|
+
"THIRD_PARTY_NOTICES.md",
|
|
21
|
+
"third-party/**",
|
|
22
|
+
"!**/*.test.ts",
|
|
23
|
+
"!test/**"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"imports": {
|
|
28
|
+
"#tools/*": {
|
|
29
|
+
"types": "./out/tools/*.d.ts",
|
|
30
|
+
"node": "./out/tools/*.js",
|
|
31
|
+
"default": "./out/tools/*.js"
|
|
32
|
+
},
|
|
33
|
+
"#*": {
|
|
34
|
+
"types": "./out/*.d.ts",
|
|
35
|
+
"node": "./out/*.js",
|
|
36
|
+
"default": "./out/*.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
"./package.json": "./package.json",
|
|
41
|
+
"./wasm/mtf.wasm": "./wasm/mtf.wasm",
|
|
42
|
+
".": {
|
|
43
|
+
"types": "./out/index.d.ts",
|
|
44
|
+
"node": "./out/index.js",
|
|
45
|
+
"default": "./out/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./tools/*": {
|
|
48
|
+
"types": "./out/tools/*.d.ts",
|
|
49
|
+
"node": "./out/tools/*.js",
|
|
50
|
+
"default": "./out/tools/*.js"
|
|
51
|
+
},
|
|
52
|
+
"./*": {
|
|
53
|
+
"types": "./out/*.d.ts",
|
|
54
|
+
"node": "./out/*.js",
|
|
55
|
+
"default": "./out/*.js"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public",
|
|
60
|
+
"exports": {
|
|
61
|
+
"./package.json": "./package.json",
|
|
62
|
+
"./wasm/mtf.wasm": "./wasm/mtf.wasm",
|
|
63
|
+
".": {
|
|
64
|
+
"types": "./out/index.d.ts",
|
|
65
|
+
"node": "./out/index.js",
|
|
66
|
+
"default": "./out/index.js"
|
|
67
|
+
},
|
|
68
|
+
"./tools/*": {
|
|
69
|
+
"types": "./out/tools/*.d.ts",
|
|
70
|
+
"node": "./out/tools/*.js",
|
|
71
|
+
"default": "./out/tools/*.js"
|
|
72
|
+
},
|
|
73
|
+
"./*": {
|
|
74
|
+
"types": "./out/*.d.ts",
|
|
75
|
+
"node": "./out/*.js",
|
|
76
|
+
"default": "./out/*.js"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"imports": {
|
|
80
|
+
"#tools/*": {
|
|
81
|
+
"types": "./out/tools/*.d.ts",
|
|
82
|
+
"node": "./out/tools/*.js",
|
|
83
|
+
"default": "./out/tools/*.js"
|
|
84
|
+
},
|
|
85
|
+
"#*": {
|
|
86
|
+
"types": "./out/*.d.ts",
|
|
87
|
+
"node": "./out/*.js",
|
|
88
|
+
"default": "./out/*.js"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"@mailwoman/core": "10.8.0",
|
|
94
|
+
"@mailwoman/query-shape": "10.8.0",
|
|
95
|
+
"path-ts": "^2.5.0",
|
|
96
|
+
"spliterator": "^10.1.1"
|
|
97
|
+
},
|
|
98
|
+
"devDependencies": {
|
|
99
|
+
"@types/node": "^26.6.6",
|
|
100
|
+
"onnxruntime-node": "^1.31.1"
|
|
101
|
+
},
|
|
102
|
+
"peerDependencies": {
|
|
103
|
+
"onnxruntime-node": "^1.26.0"
|
|
104
|
+
},
|
|
105
|
+
"peerDependenciesMeta": {
|
|
106
|
+
"onnxruntime-node": {
|
|
107
|
+
"optional": true
|
|
108
|
+
}
|
|
109
|
+
}
|
|
6
110
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Copyright (c) 2008-2011, Susumu Yata
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
|
+
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
- Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
9
|
+
|
|
10
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|