Skip to content

Commit 7955ca7

Browse files
committed
spec: add initial model config definition
Right now we define a lot of model general information as annotations. They should be defined as a field of model config. We use the guidelines below to decide if a model artifact description should be an annotation or in a structured config file: * If a description belongs to a specific layer, it SHOULD be an annotation * If a description describes a general property of the model, it SHOULD be in a config Also a `ModelFS` structure is introduced to describe the ordering of multiple layers. Fixes: #19 Fixes: #22 Signed-off-by: Peng Tao <[email protected]>
1 parent 0acf99a commit 7955ca7

File tree

3 files changed

+109
-72
lines changed

3 files changed

+109
-72
lines changed

specs-go/v1/annotations.go

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,76 +17,6 @@
1717
package v1
1818

1919
const (
20-
// AnnotationCreated is the annotation key for the date and time on which the model was built (date-time string as defined by RFC 3339).
21-
AnnotationCreated = "org.cnai.model.created"
22-
23-
// AnnotationAuthors is the annotation key for the contact details of the people or organization responsible for the model (freeform string).
24-
AnnotationAuthors = "org.cnai.model.authors"
25-
26-
// AnnotationURL is the annotation key for the URL to find more information on the model.
27-
AnnotationURL = "org.cnai.model.url"
28-
29-
// AnnotationDocumentation is the annotation key for the URL to get documentation on the model.
30-
AnnotationDocumentation = "org.cnai.model.documentation"
31-
32-
// AnnotationSource is the annotation key for the URL to get source code for building the model.
33-
AnnotationSource = "org.cnai.model.source"
34-
35-
// AnnotationVersion is the annotation key for the version of the packaged software.
36-
// The version MAY match a label or tag in the source code repository.
37-
// The version MAY be Semantic versioning-compatible.
38-
AnnotationVersion = "org.cnai.model.version"
39-
40-
// AnnotationRevision is the annotation key for the source control revision identifier for the packaged software.
41-
AnnotationRevision = "org.cnai.model.revision"
42-
43-
// AnnotationVendor is the annotation key for the name of the distributing entity, organization or individual.
44-
AnnotationVendor = "org.cnai.model.vendor"
45-
46-
// AnnotationLicenses is the annotation key for the license(s) under which contained software is distributed as an SPDX License Expression.
47-
AnnotationLicenses = "org.cnai.model.licenses"
48-
49-
// AnnotationRefName is the annotation key for the name of the reference for a target.
50-
// SHOULD only be considered valid when on descriptors on `index.json` within model layout.
51-
AnnotationRefName = "org.cnai.model.ref.name"
52-
53-
// AnnotationTitle is the annotation key for the human-readable title of the model.
54-
AnnotationTitle = "org.cnai.model.title"
55-
56-
// AnnotationDescription is the annotation key for the human-readable description of the software packaged in the model.
57-
AnnotationDescription = "org.cnai.model.description"
58-
)
59-
60-
const (
61-
// AnnotationArchitecture is the annotation key for the model architecture, such as `transformer`, `cnn`, `rnn`, etc.
62-
AnnotationArchitecture = "org.cnai.model.architecture"
63-
64-
// AnnotationFamily is the annotation key for the model family, such as `llama3`, `gpt2`, `qwen2`, etc.
65-
AnnotationFamily = "org.cnai.model.family"
66-
67-
// AnnotationName is the annotation key for the model name, such as `llama3-8b-instruct`, `gpt2-xl`, `qwen2-vl-72b-instruct`, etc.
68-
AnnotationName = "org.cnai.model.name"
69-
70-
// AnnotationFormat is the annotation key for the model format, such as `onnx`, `tensorflow`, `pytorch`, etc.
71-
AnnotationFormat = "org.cnai.model.format"
72-
73-
// AnnotationParamSize is the annotation key for the size of the model parameters.
74-
AnnotationParamSize = "org.cnai.model.param.size"
75-
76-
// AnnotationPrecision is the annotation key for the model precision, such as `bf16`, `fp16`, `int8`, etc.
77-
AnnotationPrecision = "org.cnai.model.precision"
78-
79-
// AnnotationQuantization is the annotation key for the model quantization, such as `awq`, `gptq`, etc.
80-
AnnotationQuantization = "org.cnai.model.quantization"
81-
)
82-
83-
const (
84-
// AnnotationReadme is the annotation key for the layer is a README.md file (boolean), such as `true` or `false`.
85-
AnnotationReadme = "org.cnai.model.readme"
86-
87-
// AnnotationLicense is the annotation key for the layer is a license file (boolean), such as `true` or `false`.
88-
AnnotationLicense = "org.cnai.model.license"
89-
9020
// AnnotationConfig is the annotation key for the layer is a configuration file (boolean), such as `true` or `false`.
9121
AnnotationConfig = "org.cnai.model.config"
9222

specs-go/v1/config.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright 2025 The CNAI Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"time"
21+
22+
"github.com/opencontainers/go-digest"
23+
)
24+
25+
// ModelConfig defines the execution parameters
26+
// which should be used as a base when running a model using an inference engine.
27+
type ModelConfig struct {
28+
// The model architecture, such as transformer, cnn, rnn, etc.
29+
Architecture string `json:"architecture,omitempty"`
30+
31+
// The model format, such as onnx, tensorflow, pytorch, etc.
32+
Format string `json:"format,omitempty"`
33+
34+
// The size of the model parameters
35+
ParameterSize uint64 `json:"parameterSize,omitempty"`
36+
37+
// The model precision, such as bf16, fp16, int8, mixed etc.
38+
Precision string `json:"precision,omitempty"`
39+
40+
// The model quantization, such as awq, gptq, etc
41+
Quantization string `json:"puantization,omitempty"`
42+
}
43+
44+
// ModelFS describes a layer content addresses
45+
type ModelFS struct {
46+
// Type is the type of the rootfs. MUST be set to "layers".
47+
Type string `json:"type"`
48+
49+
// DiffIDs is an array of layer content hashes (DiffIDs), in order from bottom-most to top-most.
50+
DiffIDs []digest.Digest `json:"diff_ids"`
51+
}
52+
53+
// ModelDescriptor defines the general information of a model
54+
type ModelDescriptor struct {
55+
// Date and time on which the model was built
56+
CreateTime *time.Time `json:"createTime,omitempty"`
57+
58+
// The contact details of the people or organization responsible for the model
59+
Authors []string `json:"authors,omitempty"`
60+
61+
// The model family, such as llama3, gpt2, qwen2, etc.
62+
Family string `json:"family,omitempty"`
63+
64+
// The model name, such as llama3-8b-instruct, gpt2-xl, qwen2-vl-72b-instruct, etc.
65+
Name string `json:"name,omitempty"`
66+
67+
// The URL to find more information on the model
68+
InfoURL string `json:"infoURL,omitempty"`
69+
70+
// The URL to get documentation on the model
71+
DocURL string `json:"docURL,omitempty"`
72+
73+
// The URL to get source code for building the model
74+
SourceURL string `json:"sourceURL,omitempty"`
75+
76+
// The version of the packaged software
77+
Version string `json:"version,omitempty"`
78+
79+
// The source control revision identifier for the packaged software
80+
Revision string `json:"revision,omitempty"`
81+
82+
// The name of the distributing entity, organization or individual
83+
Vendor string `json:"vendor,omitempty"`
84+
85+
// The license(s) under which contained software is distributed as an SPDX License Expression
86+
Licenses []string `json:"licenses,omitempty"`
87+
88+
// The human-readable title of the model
89+
Title string `json:"title,omitempty"`
90+
91+
// The human-readable description of the software packaged in the model
92+
Description string `json:"description,omitempty"`
93+
}
94+
95+
// Model defines the basic information of a model.
96+
// It provides the `application/vnd.cnai.model.config.v1+json` mediatype when marshalled to JSON.
97+
type Model struct {
98+
// The model descriptor
99+
Descriptor ModelDescriptor `json:"descriptor"`
100+
101+
// The model describes a layer content addresses
102+
ModelFS ModelFS `json:"modelfs"`
103+
104+
// Config defines the execution parameters which should be used as a base when running a model using an inference engine.
105+
Config ModelConfig `json:"config, omitempty"`
106+
}

specs-go/v1/mediatype.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ package v1
1919
const (
2020
// ArtifactTypeModelManifest specifies the media type for a model manifest.
2121
ArtifactTypeModelManifest = "application/vnd.cnai.model.manifest.v1+json"
22-
)
2322

24-
const (
23+
// ArtifactTypeModelConfig specifies the media type for a model configuration.
24+
ArtifactTypeModelConfig = "application/vnd.cnai.model.config.v1+json"
25+
2526
// ArtifactTypeModelLayer is the media type used for layers referenced by the manifest.
2627
ArtifactTypeModelLayer = "application/vnd.cnai.model.layer.v1.tar"
2728

0 commit comments

Comments
 (0)