|
| 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 | +} |
0 commit comments