|
3 | 3 | // without conversion. Both Docker and ModelPack formats are supported natively through |
4 | 4 | // the types.ModelConfig interface. |
5 | 5 | // |
6 | | -// Note: JSON tags in this package use camelCase (e.g., "createdAt", "paramSize") to match |
7 | | -// the CNCF ModelPack spec, which differs from Docker model-spec's snake_case convention |
8 | | -// (e.g., "context_size"). |
| 6 | +// The struct types (ModelDescriptor, ModelConfig, ModelFS, ModelCapabilities) are |
| 7 | +// re-exported directly from the official CNCF model-spec Go module so that |
| 8 | +// serialization tags and field definitions stay in sync with the specification. |
9 | 9 | // |
10 | 10 | // See: https://github.com/modelpack/model-spec |
11 | 11 | package modelpack |
12 | 12 |
|
13 | 13 | import ( |
14 | 14 | "encoding/json" |
15 | 15 | "strings" |
16 | | - "time" |
17 | 16 |
|
18 | 17 | "github.com/docker/model-runner/pkg/distribution/types" |
19 | | - "github.com/opencontainers/go-digest" |
20 | | - |
21 | 18 | specv1 "github.com/modelpack/model-spec/specs-go/v1" |
| 19 | + "github.com/opencontainers/go-digest" |
22 | 20 | ) |
23 | 21 |
|
24 | 22 | const ( |
@@ -60,6 +58,40 @@ const ( |
60 | 58 | MediaTypeWeightSafetensors = "application/vnd.cncf.model.weight.v1.safetensors" |
61 | 59 | ) |
62 | 60 |
|
| 61 | +// Type aliases re-export the canonical CNCF model-spec struct types so that |
| 62 | +// callers use the upstream definitions (and their JSON tags) by default. |
| 63 | +// This eliminates local struct duplication while keeping the modelpack |
| 64 | +// package as the single import for DMR code. |
| 65 | +type ( |
| 66 | + // ModelDescriptor defines the general information of a model. |
| 67 | + ModelDescriptor = specv1.ModelDescriptor |
| 68 | + |
| 69 | + // ModelConfig defines the execution parameters for an inference engine. |
| 70 | + ModelConfig = specv1.ModelConfig |
| 71 | + |
| 72 | + // ModelFS describes the layer content addresses. |
| 73 | + ModelFS = specv1.ModelFS |
| 74 | + |
| 75 | + // ModelCapabilities defines the special capabilities that the model supports. |
| 76 | + ModelCapabilities = specv1.ModelCapabilities |
| 77 | +) |
| 78 | + |
| 79 | +// Model represents the CNCF ModelPack config structure. |
| 80 | +// It provides the `application/vnd.cncf.model.config.v1+json` mediatype when marshalled to JSON. |
| 81 | +// |
| 82 | +// The struct mirrors specv1.Model but is declared as its own named type so |
| 83 | +// that it can implement the types.ModelConfig interface required by DMR. |
| 84 | +type Model struct { |
| 85 | + // Descriptor provides metadata about the model provenance and identity. |
| 86 | + Descriptor ModelDescriptor `json:"descriptor"` |
| 87 | + |
| 88 | + // ModelFS describes the layer content addresses. |
| 89 | + ModelFS ModelFS `json:"modelfs"` |
| 90 | + |
| 91 | + // Config defines the execution parameters for the model. |
| 92 | + Config ModelConfig `json:"config,omitempty"` |
| 93 | +} |
| 94 | + |
63 | 95 | // IsModelPackWeightMediaType checks if the given media type is a CNCF ModelPack weight layer type. |
64 | 96 | // This includes both format-specific types (e.g., .gguf, .safetensors) and |
65 | 97 | // format-agnostic types from the official model-spec (e.g., .raw, .tar). |
@@ -126,121 +158,6 @@ func IsModelPackConfig(raw []byte) bool { |
126 | 158 | return false |
127 | 159 | } |
128 | 160 |
|
129 | | -// Model represents the CNCF ModelPack config structure. |
130 | | -// It provides the `application/vnd.cncf.model.config.v1+json` mediatype when marshalled to JSON. |
131 | | -type Model struct { |
132 | | - // Descriptor provides metadata about the model provenance and identity. |
133 | | - Descriptor ModelDescriptor `json:"descriptor"` |
134 | | - |
135 | | - // ModelFS describes the layer content addresses. |
136 | | - ModelFS ModelFS `json:"modelfs"` |
137 | | - |
138 | | - // Config defines the execution parameters for the model. |
139 | | - Config ModelConfig `json:"config,omitempty"` |
140 | | -} |
141 | | - |
142 | | -// ModelDescriptor defines the general information of a model. |
143 | | -type ModelDescriptor struct { |
144 | | - // CreatedAt is the date and time on which the model was built. |
145 | | - CreatedAt *time.Time `json:"createdAt,omitempty"` |
146 | | - |
147 | | - // Authors contains the contact details of the people or organization responsible for the model. |
148 | | - Authors []string `json:"authors,omitempty"` |
149 | | - |
150 | | - // Family is the model family, such as llama3, gpt2, qwen2, etc. |
151 | | - Family string `json:"family,omitempty"` |
152 | | - |
153 | | - // Name is the model name, such as llama3-8b-instruct, gpt2-xl, etc. |
154 | | - Name string `json:"name,omitempty"` |
155 | | - |
156 | | - // DocURL is the URL to get documentation on the model. |
157 | | - DocURL string `json:"docURL,omitempty"` |
158 | | - |
159 | | - // SourceURL is the URL to get source code for building the model. |
160 | | - SourceURL string `json:"sourceURL,omitempty"` |
161 | | - |
162 | | - // DatasetsURL contains URLs referencing datasets that the model was trained upon. |
163 | | - DatasetsURL []string `json:"datasetsURL,omitempty"` |
164 | | - |
165 | | - // Version is the version of the packaged software. |
166 | | - Version string `json:"version,omitempty"` |
167 | | - |
168 | | - // Revision is the source control revision identifier for the packaged software. |
169 | | - Revision string `json:"revision,omitempty"` |
170 | | - |
171 | | - // Vendor is the name of the distributing entity, organization or individual. |
172 | | - Vendor string `json:"vendor,omitempty"` |
173 | | - |
174 | | - // Licenses contains the license(s) under which contained software is distributed |
175 | | - // as an SPDX License Expression. |
176 | | - Licenses []string `json:"licenses,omitempty"` |
177 | | - |
178 | | - // Title is the human-readable title of the model. |
179 | | - Title string `json:"title,omitempty"` |
180 | | - |
181 | | - // Description is the human-readable description of the software packaged in the model. |
182 | | - Description string `json:"description,omitempty"` |
183 | | -} |
184 | | - |
185 | | -// ModelConfig defines the execution parameters which should be used as a base |
186 | | -// when running a model using an inference engine. |
187 | | -type ModelConfig struct { |
188 | | - // Architecture is the model architecture, such as transformer, cnn, rnn, etc. |
189 | | - Architecture string `json:"architecture,omitempty"` |
190 | | - |
191 | | - // Format is the model format, such as gguf, safetensors, onnx, etc. |
192 | | - Format string `json:"format,omitempty"` |
193 | | - |
194 | | - // ParamSize is the size of the model parameters, such as "8b", "16b", "32b", etc. |
195 | | - ParamSize string `json:"paramSize,omitempty"` |
196 | | - |
197 | | - // Precision is the model precision, such as bf16, fp16, int8, mixed etc. |
198 | | - Precision string `json:"precision,omitempty"` |
199 | | - |
200 | | - // Quantization is the model quantization method, such as awq, gptq, etc. |
201 | | - Quantization string `json:"quantization,omitempty"` |
202 | | - |
203 | | - // Capabilities defines special capabilities that the model supports. |
204 | | - Capabilities *ModelCapabilities `json:"capabilities,omitempty"` |
205 | | -} |
206 | | - |
207 | | -// ModelCapabilities defines the special capabilities that the model supports. |
208 | | -type ModelCapabilities struct { |
209 | | - // InputTypes specifies what input modalities the model can process. |
210 | | - // Values can be: "text", "image", "audio", "video", "embedding", "other". |
211 | | - InputTypes []string `json:"inputTypes,omitempty"` |
212 | | - |
213 | | - // OutputTypes specifies what output modalities the model can produce. |
214 | | - // Values can be: "text", "image", "audio", "video", "embedding", "other". |
215 | | - OutputTypes []string `json:"outputTypes,omitempty"` |
216 | | - |
217 | | - // KnowledgeCutoff is the date of the datasets that the model was trained on. |
218 | | - KnowledgeCutoff *time.Time `json:"knowledgeCutoff,omitempty"` |
219 | | - |
220 | | - // Reasoning indicates whether the model can perform reasoning tasks. |
221 | | - Reasoning *bool `json:"reasoning,omitempty"` |
222 | | - |
223 | | - // ToolUsage indicates whether the model can use external tools. |
224 | | - ToolUsage *bool `json:"toolUsage,omitempty"` |
225 | | - |
226 | | - // Reward indicates whether the model is a reward model. |
227 | | - Reward *bool `json:"reward,omitempty"` |
228 | | - |
229 | | - // Languages indicates the languages that the model can speak. |
230 | | - // Encoded as ISO 639 two letter codes. For example, ["en", "fr", "zh"]. |
231 | | - Languages []string `json:"languages,omitempty"` |
232 | | -} |
233 | | - |
234 | | -// ModelFS describes the layer content addresses. |
235 | | -type ModelFS struct { |
236 | | - // Type is the type of the rootfs. MUST be set to "layers". |
237 | | - Type string `json:"type"` |
238 | | - |
239 | | - // DiffIDs is an array of layer content hashes (DiffIDs), |
240 | | - // in order from bottom-most to top-most. |
241 | | - DiffIDs []digest.Digest `json:"diffIds"` |
242 | | -} |
243 | | - |
244 | 161 | // Ensure Model implements types.ModelConfig |
245 | 162 | var _ types.ModelConfig = (*Model)(nil) |
246 | 163 |
|
|
0 commit comments