Documentation
¶
Index ¶
- func ComputeCompositeHash(files []HashManifestFile) string
- func DownloadModel(ctx context.Context, files []ModelFile, destDir string) error
- func DownloadModelAndSaveManifest(ctx context.Context, modelID string, files []ModelFile, destDir string) error
- func HuggingFaceModelSize(files []ModelFile) int64
- func SaveHashManifest(modelID, destDir string, files []ModelFile) error
- type Account
- type CatalogModel
- type CatalogResponse
- type ClusterResource
- type CollectNodeInfo
- type Common
- type CpInfoEntity
- type CpuQuota
- type Gpu
- type GpuDetail
- type GpuQuota
- type GpuStatus
- type HFLFS
- type HFModelInfo
- type HFSibling
- type HashManifest
- type HashManifestFile
- type HostInfo
- type ModelFile
- type ModelFilesResponse
- type NodeResource
- type Quota
- type ResourcePolicy
- type ResourceStatus
- type VerifyResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeCompositeHash ¶
func ComputeCompositeHash(files []HashManifestFile) string
ComputeCompositeHash computes a deterministic composite hash from per-file hashes. Algorithm: sort filenames alphabetically, concatenate "filename:hash\n" strings, SHA256 the result. This must match the server-side algorithm in swan-inference.
func DownloadModel ¶
DownloadModel downloads all model files to destDir. It skips files that already exist with the correct size and hash.
func DownloadModelAndSaveManifest ¶
func DownloadModelAndSaveManifest(ctx context.Context, modelID string, files []ModelFile, destDir string) error
DownloadModelAndSaveManifest downloads a model and saves the hash manifest. This is the recommended entry point for model downloads.
func HuggingFaceModelSize ¶
HuggingFaceModelSize returns the total size of all files.
func SaveHashManifest ¶
SaveHashManifest saves a hash manifest for a downloaded model. Should be called after DownloadModel() succeeds.
Types ¶
type CatalogModel ¶
type CatalogModel struct {
ModelID string `json:"model_id"`
Name string `json:"name"`
Category string `json:"category"`
FileCount int `json:"file_count"`
TotalSizeBytes int64 `json:"total_size_bytes"`
WeightSourceURL string `json:"weight_source_url,omitempty"`
}
CatalogModel represents a model available in the Swan Model Repository.
type CatalogResponse ¶
type CatalogResponse struct {
Models []CatalogModel `json:"models"`
Total int `json:"total"`
}
CatalogResponse is the response from GET /api/v1/models/catalog.
func FetchCatalog ¶
func FetchCatalog(serviceURL string) (*CatalogResponse, error)
FetchCatalog calls the swan-inference API to get the list of available models.
type ClusterResource ¶
type ClusterResource struct {
NodeId string `json:"node_id,omitempty"`
CpAccountAddress string `json:"cpAccount_address"`
Region string `json:"region,omitempty"`
ClusterInfo []*NodeResource `json:"cluster_info"`
NodeName string `json:"node_name,omitempty"`
Runtime string `json:"runtime,omitempty"`
ClientType string `json:"client_type"`
}
type CollectNodeInfo ¶
type CpInfoEntity ¶
type CpInfoEntity struct {
Id int64 `json:"id" gorm:"primaryKey;autoIncrement"`
NodeId string `json:"node_id" gorm:"node_id"`
OwnerAddress string `json:"owner_address" gorm:"owner_address"`
Beneficiary string `json:"beneficiary" gorm:"beneficiary"`
WorkerAddress string `json:"worker_address" gorm:"worker_address"`
Version string `json:"version" gorm:"version"`
ContractAddress string `json:"contract_address" gorm:"contract_address"`
MultiAddressesJSON string `gorm:"multi_addresses_json;type:text" json:"-"`
TaskTypesJSON string `gorm:"task_types_json; type:text" json:"-"`
CreateAt string `json:"create_at" gorm:"create_at"`
UpdateAt string `json:"update_at" gorm:"update_at"`
MultiAddresses []string `json:"multi_addresses" gorm:"-"`
TaskTypes []uint8 `json:"task_types" gorm:"-"`
}
func (*CpInfoEntity) BeforeSave ¶
func (c *CpInfoEntity) BeforeSave(tx *gorm.DB) (err error)
func (*CpInfoEntity) TableName ¶
func (*CpInfoEntity) TableName() string
type HFModelInfo ¶
type HFModelInfo struct {
Siblings []HFSibling `json:"siblings"`
}
HFModelInfo is the response from the HuggingFace model API.
type HFSibling ¶
type HFSibling struct {
RFilename string `json:"rfilename"`
Size int64 `json:"size"`
LFS *HFLFS `json:"lfs,omitempty"`
}
HFSibling represents a file in a HuggingFace model repository.
type HashManifest ¶
type HashManifest struct {
ModelID string `json:"model_id"`
CompositeHash string `json:"composite_hash"`
Algorithm string `json:"algorithm"`
Files []HashManifestFile `json:"files"`
CreatedAt string `json:"created_at"`
}
HashManifest stores per-file hashes and a composite hash for model weight verification. Saved as .swan-hash-manifest.json in the model directory.
func LoadHashManifest ¶
func LoadHashManifest(destDir string) (*HashManifest, error)
LoadHashManifest loads a hash manifest from a model directory. Returns nil, nil if the manifest does not exist.
type HashManifestFile ¶
type HashManifestFile struct {
Filename string `json:"filename"`
Hash string `json:"hash"`
SizeBytes int64 `json:"size_bytes"`
}
HashManifestFile describes a single file's hash in the manifest
type ModelFile ¶
type ModelFile struct {
Filename string `json:"filename"`
Hash string `json:"hash"`
Algorithm string `json:"algorithm"`
SizeBytes int64 `json:"size_bytes"`
URL string `json:"url"`
}
ModelFile represents a single file in a model's weight repository.
func FetchHuggingFaceFiles ¶
FetchHuggingFaceFiles fetches the file list for a model from HuggingFace.
type ModelFilesResponse ¶
type ModelFilesResponse struct {
ModelID string `json:"model_id"`
Files []ModelFile `json:"files"`
TotalSizeBytes int64 `json:"total_size_bytes"`
FileCount int `json:"file_count"`
}
ModelFilesResponse is the response from GET /api/v1/models/:model_id/files.
func FetchModelFiles ¶
func FetchModelFiles(serviceURL, modelID string) (*ModelFilesResponse, error)
FetchModelFiles calls the swan-inference API to get the file manifest for a model.
type NodeResource ¶
type ResourcePolicy ¶
type ResourceStatus ¶
type VerifyResult ¶
type VerifyResult struct {
Filename string
Status string // "pass", "fail", "missing"
Expected string
Actual string
}
VerifyResult describes the result of verifying a single file.
func VerifyModel ¶
func VerifyModel(files []ModelFile, destDir string) []VerifyResult
VerifyModel checks each local file against expected hashes.