models

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

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

func DownloadModel(ctx context.Context, files []ModelFile, destDir string) error

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

func HuggingFaceModelSize(files []ModelFile) int64

HuggingFaceModelSize returns the total size of all files.

func SaveHashManifest

func SaveHashManifest(modelID, destDir string, files []ModelFile) error

SaveHashManifest saves a hash manifest for a downloaded model. Should be called after DownloadModel() succeeds.

Types

type Account

type Account struct {
	OwnerAddress   string
	NodeId         string
	MultiAddresses []string
	TaskTypes      []uint8
	Beneficiary    string
	WorkerAddress  string
	Version        string
	Contract       string
}

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 CollectNodeInfo struct {
	Gpu         Gpu    `json:"gpu"`
	CpuName     string `json:"cpu_name"`
	ProductUuid string `json:"product_uuid"`
	MachineId   string `json:"machine_id"`
}

type Common

type Common struct {
	Total        string `json:"total"`
	Used         string `json:"used"`
	Free         string `json:"free"`
	RemainderNum int64  `json:"-"`
}

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) AfterFind

func (c *CpInfoEntity) AfterFind(tx *gorm.DB) (err error)

func (*CpInfoEntity) BeforeSave

func (c *CpInfoEntity) BeforeSave(tx *gorm.DB) (err error)

func (*CpInfoEntity) TableName

func (*CpInfoEntity) TableName() string

type CpuQuota

type CpuQuota struct {
	Quota int64 `json:"quota"`
}

type Gpu

type Gpu struct {
	DriverVersion string      `json:"driver_version"`
	CudaVersion   string      `json:"cuda_version"`
	AttachedGpus  int         `json:"attached_gpus"`
	Details       []GpuDetail `json:"details"`
}

type GpuDetail

type GpuDetail struct {
	ProductName   string    `json:"product_name"`
	Status        GpuStatus `json:"status"`
	FbMemoryUsage Common    `json:"fb_memory_usage"`
	OriginalName  string    `json:"original_name"`
	Index         string    `json:"index"`
	Guid          string    `json:"guid"`
}

type GpuQuota

type GpuQuota struct {
	Name  string `json:"name"`
	Quota int64  `json:"quota"`
}

type GpuStatus

type GpuStatus string
const (
	Occupied  GpuStatus = "occupied"
	Available GpuStatus = "available"
)

type HFLFS

type HFLFS struct {
	SHA256 string `json:"sha256"`
	Size   int64  `json:"size"`
}

HFLFS contains LFS metadata for a file.

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 HostInfo

type HostInfo struct {
	SwanProviderVersion string `json:"swan_miner_version"`
	OperatingSystem     string `json:"operating_system"`
	Architecture        string `json:"architecture"`
	CPUCores            int    `json:"cpu_cores"`
}

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

func FetchHuggingFaceFiles(modelID string) ([]ModelFile, error)

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 NodeResource struct {
	ProductUuid string `json:"product_uuid"`
	MachineId   string `json:"machine_id"`
	CpuName     string `json:"cpu_name"`
	Cpu         Common `json:"cpu"`
	Vcpu        Common `json:"vcpu"`
	Memory      Common `json:"memory"`
	Gpu         Gpu    `json:"gpu"`
	Storage     Common `json:"storage"`
	Code        string `json:"code"`
}

type Quota

type Quota struct {
	Quota int64  `json:"quota"`
	Unit  string `json:"unit"`
}

type ResourcePolicy

type ResourcePolicy struct {
	Cpu     CpuQuota   `json:"cpu"`
	Gpu     []GpuQuota `json:"gpu"`
	Memory  Quota      `json:"memory"`
	Storage Quota      `json:"storage"`
}

type ResourceStatus

type ResourceStatus struct {
	Request  int64
	Capacity int64
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL