Documentation
¶
Index ¶
Constants ¶
const ( // File size thresholds and workspace limits WeightFileSizeThreshold int64 = 512 * humanize.MByte // 512MB - threshold for considering file as weight file MaxSingleFileSize int64 = 512 * humanize.GByte // 512GB - maximum size for a single file MaxWorkspaceFileCount int = 4096 // 4096 files - maximum number of files in workspace MaxTotalWorkspaceSize int64 = 32 * humanize.TByte // 32TB - maximum total workspace size )
Variables ¶
var ( // Config file patterns - supported configuration file extensions. ConfigFilePatterns = []string{ "*.json", "*.jsonl", "*.json5", "*.jsonc", "*.yaml", "*.yml", "*.toml", "*.ini", "*.config", "*.cfg", "*.conf", "*.properties", "*.props", "*.prop", "*.xml", "*.xsd", "*.rng", "*.modelcard", "*.meta", "*tokenizer.model*", "*.tiktoken", "vocab.txt", "merges.txt", "added_tokens.txt", "spiece.model", "sentencepiece*.model", "sentencepiece*.vocab", "tiktoken.model", "chat_template.jinja", "config.json.*", "*.hparams", "*.params", "*.hyperparams", "*.wandb", "*.mlflow", "*.tensorboard", } // Model file patterns - supported model file extensions. ModelFilePatterns = []string{ "*.safetensors", "*.bin", "*.bin.*", "*.pt", "*.pth", "*.mar", "*.pte", "*.pt2", "*.ptl", "*.tflite", "*.h5", "*.hdf", "*.hdf5", "*.pb", "*.meta", "*.data-*", "*.index", "*.gguf", "*.gguf.*", "*.ggml", "*.ggmf", "*.ggjt", "*.q4_0", "*.q4_1", "*.q5_0", "*.q5_1", "*.q8_0", "*.f16", "*.f32", "*.ckpt", "*.checkpoint", "*.dist_ckpt", "tensor[0-9]*_[0-9]*", "*.tensor", "*.weights", "*.state", "*.embedding", "*.vocab", "*.ot", "*.engine", "*.trt", "*.onnx", "*.onnx_data*", "*.msgpack", "*.model", "*.pkl", "*.pickle", "*.keras", "*.joblib", "*.npy", "*.npz", "*.nc", "*.mlmodel", "*.coreml", "*.mil", "*.mleap", "*.surml", "*.llamafile", "*.llamafile.*", "*.caffemodel", "*.prototxt", "*.dlc", "*.circle", "*.nb", "*.arrow", "*.parquet", "*.ftz", "*.ark", "*.db", "feature_map", "checkpoint", } // Code file patterns - supported script and notebook files. CodeFilePatterns = []string{}/* 140 elements not displayed */ // Doc file patterns - supported documentation files DocFilePatterns = []string{}/* 104 elements not displayed */ )
Functions ¶
func ExtractONNXExternalDataPaths ¶ added in v0.2.3
ExtractONNXExternalDataPaths parses the ONNX model file at onnxPath and returns the relative paths of all external_data tensor files referenced by it.
Paths are returned exactly as recorded in the ONNX file (relative to the directory containing the .onnx file, per ONNX convention). The slice is deduplicated and ordered by first appearance.
An ONNX without any external_data references returns nil, nil. The function returns an error for: I/O failures (stat / read), files exceeding onnxMaxParseSize, and malformed protobuf wire data (e.g., truncated or corrupted bytes). Callers that want best-effort behavior should treat all errors as a fallback signal and continue without external_data information.
func IsFileType ¶
IsFileType checks if the filename matches any of the given patterns
func SizeShouldBeWeightFile ¶
For large unknown file type, usually it is a weight file.
Types ¶
type FileType ¶ added in v0.2.1
type FileType int
FileType represents the inferred type of a file.
func InferFileType ¶ added in v0.2.1
InferFileType determines the file type by extension matching first, then falls back to a size-based heuristic for unrecognized files: >128MB -> FileTypeModel, otherwise -> FileTypeCode.
type Modelfile ¶
type Modelfile interface {
// GetConfigs returns the args of the config command in the modelfile,
// and deduplicates the args. The order of the args is the same as the
// order in the modelfile.
GetConfigs() []string
// GetModels returns the args of the model command in the modelfile,
// and deduplicates the args. The order of the args is the same as the
// order in the modelfile.
GetModels() []string
// GetCode returns the args of the code command in the modelfile,
// and deduplicates the args. The order of the args is the same as the
// order in the modelfile.
GetCodes() []string
// GetDatasets returns the args of the dataset command in the modelfile,
// and deduplicates the args. The order of the args is the same as the
// order in the modelfile.
GetDatasets() []string
// GetDocs returns the args of the doc command in the modelfile,
// and deduplicates the args. The order of the args is the same as the
// order in the modelfile.
GetDocs() []string
// GetName returns the value of the name command in the modelfile.
GetName() string
// GetArch returns the value of the arch command in the modelfile.
GetArch() string
// GetFamily returns the value of the family command in the modelfile.
GetFamily() string
// GetFormat returns the value of the format command in the modelfile.
GetFormat() string
// GetParamsize returns the value of the paramsize command in the modelfile.
GetParamsize() string
// GetPrecision returns the value of the precision command in the modelfile.
GetPrecision() string
// GetQuantization returns the value of the quantization command in the modelfile.
GetQuantization() string
// Content returns the content of the modelfile.
Content() []byte
}
Modelfile is the interface for the modelfile. It is used to parse the modelfile by the path and get the information of the modelfile.
func NewModelfile ¶
NewModelfile creates a new modelfile by the path of the modelfile. It parses the modelfile and returns the modelfile interface.
func NewModelfileByWorkspace ¶
func NewModelfileByWorkspace(workspace string, config *configmodelfile.GenerateConfig) (Modelfile, error)
NewModelfileByWorkspace creates a new modelfile by the workspace.
It generates the modelfile by the following steps:
- It walks the workspace and gets the files, and generates the modelfile by the files.
- It generates the modelfile by the model config, such as config.json and generation_config.json.
- It generates the modelfile by the generate config, such as name, arch, family, format, paramsize, precision, and quantization.
type PathFilter ¶ added in v0.1.1
type PathFilter struct {
// contains filtered or unexported fields
}
func NewPathFilter ¶ added in v0.1.1
func NewPathFilter(excludePatterns []string, includePatterns []string) (*PathFilter, error)
func (*PathFilter) Match ¶ added in v0.1.1
func (pf *PathFilter) Match(path string) bool
Match checks if a path matches any exclude pattern.
func (*PathFilter) MatchInclude ¶ added in v0.2.1
func (pf *PathFilter) MatchInclude(relPath string) bool
MatchInclude checks if a relative path matches any include pattern.
func (*PathFilter) ShouldDescend ¶ added in v0.2.1
func (pf *PathFilter) ShouldDescend(dirRelPath string) bool
ShouldDescend checks if a skippable directory should be entered because an include pattern might match files inside it.