Weights from Hugging Face pinned to a commit and checked against the sha256 it published

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-30 07:33:15 +01:00
1 parent 29d7f54cfd
commit b8ed368e31
22 files changed
+578 -16

No files matched your search

+28 -2
View File
@@ -16,6 +16,7 @@ import (
"github.com/spf13/cobra"
"gitea.mynodes.xyz/ilker/llmgw/internal/control/adminapi"
"gitea.mynodes.xyz/ilker/llmgw/internal/hf"
"gitea.mynodes.xyz/ilker/llmgw/internal/mirror"
"gitea.mynodes.xyz/ilker/llmgw/internal/tlsconf"
)
@@ -57,7 +58,7 @@ func newMirrorCmd() *cobra.Command {
}
func newMirrorAddCmd(dir *string) *cobra.Command {
var model, version, as string
var model, version, as, sha, registry string
c := &cobra.Command{
Use: "add <url>...",
@@ -79,7 +80,7 @@ func newMirrorAddCmd(dir *string) *cobra.Command {
if model == "" || version == "" {
return fmt.Errorf("--model and --version are required: they are the layout")
}
if as != "" && len(args) > 1 {
if (as != "" || sha != "") && len(args) > 1 {
return fmt.Errorf("--as names one file; with %d URLs each keeps its own name", len(args))
}
out := cmd.OutOrStdout()
@@ -90,6 +91,21 @@ func newMirrorAddCmd(dir *string) *cobra.Command {
file = mirror.LastPathElement(source)
}
e := mirror.Entry{Model: model, Version: version, File: file}
// From the registry: what it published for the file, to
// compare with what arrives.
want := strings.ToLower(sha)
if id, rev, path, ok := hf.FileSource(source, registry); ok && want == "" {
repo, err := hf.New(registry, 30*time.Second).RepoAt(cmd.Context(), id, rev)
if err != nil {
return fmt.Errorf("looking up %s in the registry, for the sha256 it published: %w "+
"(--sha256 gives it instead)", id, err)
}
for _, f := range repo.Files {
if f.Path == path {
want = f.SHA256
}
}
}
fmt.Fprintf(out, "fetching %s\n", source)
added, err := mirror.Add(cmd.Context(), *dir, source, e, func(done, total int64) {
if total > 0 {
@@ -102,6 +118,14 @@ func newMirrorAddCmd(dir *string) *cobra.Command {
if err != nil {
return err
}
if want != "" && added.SHA256 != want {
_ = mirror.Remove(*dir, e)
return fmt.Errorf("%s arrived with sha256 %s, and %s was published for it: deleted",
source, added.SHA256, want)
}
if want != "" {
fmt.Fprintln(out, " sha256 matches the one published")
}
fmt.Fprintf(out, "%s/%s/%s %s\n sha256 %s\n",
added.Entry.Model, added.Entry.Version, added.Entry.File,
fileSize(added.Entry.Bytes), added.SHA256)
@@ -123,6 +147,8 @@ func newMirrorAddCmd(dir *string) *cobra.Command {
c.Flags().StringVar(&model, "model", "", "the model's name, one directory level")
c.Flags().StringVar(&version, "version", "", "the version, one directory level; a date works well")
c.Flags().StringVar(&as, "as", "", "the filename to save as, for one URL; taken from the URL when omitted")
c.Flags().StringVar(&sha, "sha256", "", "the sha256 the file must have, for one URL; looked up for a Hugging Face URL")
c.Flags().StringVar(&registry, "registry", hf.DefaultEndpoint, "the registry a resolve URL is looked up in")
return c
}
+3
View File
@@ -453,6 +453,9 @@ func newServerCmd() *cobra.Command {
if st := rt.Store(); st != nil {
svc := modelsvc.New(cfg.Models, st, admin, log)
svc.SetCheck(servableCheck(cfg.WantedEngines()["llamacpp"]))
// What is added from the registry is pinned to the
// commit it is at, with each file's sha256 for the nodes.
svc.SetRegistry(hf.New(cfg.Mirror.Registry, 30*time.Second))
// Other llmgw clusters' models, offered as PEER/MODEL:
// read before the catalog is built, so a model that falls
// back to one is whole at startup.