-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-kitfile.js
More file actions
82 lines (75 loc) · 2.3 KB
/
build-kitfile.js
File metadata and controls
82 lines (75 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env node
/**
* Build a Kitfile programmatically and pack it.
*
* Useful when you want to generate the Kitfile from existing metadata (e.g. a
* training config, a model card, or package.json) rather than maintaining it
* as a static file in version control.
*
* This example includes a local `buildKitfile` helper that serializes a config
* object to YAML. You can copy it into your own project as-is — it only needs
* the `yaml` package, which is already a dependency of kitops-ts.
*
* Run: node examples/build-kitfile.js
*/
import { writeFile } from 'fs/promises';
import { stringify as toYaml } from 'yaml';
import { pack } from '../dist/index.js';
/**
* Serializes a Kitfile config to a YAML string ready to be written to disk.
* `manifestVersion` defaults to '1.0.0' when not provided.
*
* @param {object} config - A Kitfile-shaped object (see Kitfile type in the library).
* @returns {string} YAML string.
*/
function buildKitfile({ manifestVersion = '1.0.0', ...rest }) {
return toYaml({ manifestVersion, ...rest }, { lineWidth: 0 });
}
// ---
const registry = process.env.REGISTRY ?? 'registry.example.com';
const version = process.env.MODEL_VERSION ?? '1.0.0';
const tag = `${registry}/org/sentiment-model:v${version}`;
const yaml = buildKitfile({
package: {
name: 'sentiment-model',
version,
description: 'Fine-tuned sentiment classification model',
authors: ['ML Team'],
license: 'Apache-2.0',
},
model: {
name: 'sentiment-classifier',
path: './model/weights.pt',
format: 'pytorch',
parameters: {
architecture: 'bert-base',
layers: 12,
hiddenSize: 768,
},
},
datasets: [
{
name: 'training-set',
path: './data/train.csv',
description: 'Labeled training examples (80/20 split)',
license: 'CC-BY-4.0',
},
{
name: 'validation-set',
path: './data/val.csv',
description: 'Held-out validation set',
license: 'CC-BY-4.0',
},
],
code: [
{ path: './src/train.py', description: 'Training entry point' },
{ path: './src/infer.py', description: 'Inference entry point' },
],
docs: [
{ path: './README.md', description: 'Model card' },
],
});
await writeFile('./Kitfile', yaml);
console.log('Kitfile written.');
await pack('.', { tag });
console.log(`Packed: ${tag}`);