huggingface

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package huggingface owns the current Machine Learning layout used by Hugging Face model and dataset repositories: each model or dataset lives under its own folder <kind>--<owner>--<name> (models--acme--demo), with its files at snapshots/<40-hex-revision>/<file>, its named refs at refs/<name>, and its Xet records in a private .xet folder. Its hooks admit only that layout and rebuild the package index from the committed snapshots, and keep raw Xet records away from every generic route.

Role

artifacts module, ecosystem layer: the storage layout and admission rules of the Hugging Face slice (package type huggingfaceml). Its Handler plugs into the item service through the format hooks (decision 0032); the slice's http package (artifacts/ecosystem/huggingface/http) serves the Hub, Xet and legacy-migration protocol over what it keeps, and the Xet wire formats are the xet package's.

Inputs

  • Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for huggingfaceml repositories to Handler, and the work queue, which runs every format's reindex through it; and the protocol, which parses and builds identities and paths (ParseIdentity, SnapshotPath, ParseSnapshotPath, RefPath, ParseRefPath, Revision, RefName, FilePath) and marks its own writes (XetWrite, DeferReindex).
  • Driven: the format hooks' environment (format.Env), through which Handler lists a repository's snapshot files and keeps the package index (artifacts/core/pkgindex); the generic deploy policy (artifacts/ecosystem/generic), which Handler embeds and whose blackout and include and exclude checks it applies; and the xet package, whose hash grammar a Xet record's path must follow.
  • Settings: none.

Outputs

  • Handler: the hooks that admit a write only in the current layout (Admit), keep Xet records off copy, move and download (GuardTransferSource, Resolve), rebuild the index after a snapshot file is written or removed (Deployed, Deleting, Deleted, Reindex) and class each path (Classify).
  • The package index: a package per model or dataset, named <kind>/<owner>/<name>, with a version per committed revision, whose metadata lists the revision's files.
  • The layout rules the protocol shares: Identity, ParseIdentity, Revision, RefName, FilePath, SnapshotPath, ParseSnapshotPath, RefPath, ParseRefPath, IsXetPath and ValidXetPath.

Invariants

  • A model and a dataset with the same Hub ID stay disjoint, and the superseded legacy layout is never read as the current one.
  • Only a write the protocol marked with XetWrite reaches a Xet record, and generic downloads, copies and moves never expose one.
  • The index is rebuilt from the tree, so a delete, restore or move never leaves a stale revision.

References

Status

Implemented P9c, which delivered the plan's P32 group (issues #777 to #780 and #789). Moved here in P9d.

Testing

  • path_test.go: identities, snapshot and ref paths, and the legacy layout and malformed names that stay outside the current layout.
  • handler_test.go: admission with the repository's policy, the lifecycle hooks, the reindex fence and storage failures.
  • xet_test.go: the private .xet layout's boundaries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeferReindex

func DeferReindex(ctx context.Context) context.Context

DeferReindex lets a native multi-file commit publish its snapshot before rebuilding the package index once inside the same transaction.

func FilePath

func FilePath(s string) bool

FilePath refuses traversal and control characters while preserving valid Unicode filenames used by model repositories.

func IsXetPath

func IsXetPath(path string) bool

IsXetPath reports whether path lies in an identity's private .xet folder, whatever follows it, so the hooks refuse every generic access to it, a malformed record path included.

func RefName

func RefName(s string) bool

RefName is the documented branch/tag grammar. A ref points to an immutable full revision; its name is never interpreted as a filesystem traversal.

func RefPath

func RefPath(id Identity, name string) (string, bool)

RefPath is the item path of id's named ref name, <prefix>/refs/<name>, which holds the full revision the ref points at. ok is false for a name outside the ref grammar (RefName) and for a full revision, which names a commit rather than a ref.

func Revision

func Revision(s string) bool

Revision accepts immutable full commit IDs. main is a mutable ref resolved before a snapshot path is built. The wire permits a branch or tag name, but only a published ref is resolved; it is never treated as a file-system path.

func Serves

func Serves(t repo.PackageType) bool

Serves reports whether t is the package type this format handles, huggingfaceml.

func SnapshotPath

func SnapshotPath(id Identity, revision, file string) (string, bool)

SnapshotPath returns the canonical item path for one file.

func ValidXetPath

func ValidXetPath(path string) bool

ValidXetPath reports whether path names one Xet record, <prefix>/.xet/<kind>/<hash>: a prefix whose identity ParseIdentity accepts, a kind of xorbs, files, sha256 or stages, and a hash in Xet's textual form (xet.ParseHash).

func XetWrite

func XetWrite(ctx context.Context) context.Context

XetWrite marks a validated CAS publication; HTTP properties cannot opt in.

Types

type Handler

type Handler struct{ generic.Handler }

Handler is the Hugging Face format: the generic deploy policy, which it embeds, with the hooks that keep the current layout and rebuild the package index from the committed snapshots.

func (Handler) Admit

func (Handler) Admit(
	ctx context.Context,
	_ format.Env,
	c repo.Config,
	w format.Write,
) (format.Write, error)

Admit refuses a write outside the current layout before the repository's policy is applied. A write into a .xet folder must be a deploy that the protocol marked with XetWrite, at a valid record path, or it is refused with 403; any other write but a checksum update or a remote cache write must be a snapshot file or a named ref, or it is refused with 409. Then the generic blackout and include and exclude checks refuse the write with their own answers, unwrapped. The write is returned unchanged.

func (Handler) Classify

func (Handler) Classify(_ repo.Config, path string) format.Class

Classify reports a snapshot file as unique, since a revision's files never change under their path, and every other path (a named ref, a Xet record) as metadata.

func (Handler) Deleted

func (h Handler) Deleted(
	ctx context.Context,
	env format.Env,
	c repo.Config,
	removed []model.Item,
) error

Deleted rebuilds the repository's index (Reindex) when a delete or a move took at least one snapshot file, so no revision outlives its files.

func (Handler) Deleting

Deleting does nothing: the index is rebuilt once the files are gone, in Deleted.

func (Handler) Deployed

func (h Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it model.Item) error

Deployed rebuilds the repository's index (Reindex) after a snapshot file is written, unless the context carries DeferReindex, whose caller rebuilds it once in the same transaction. Folders, refs and Xet records leave the index alone.

func (Handler) GuardTransferSource

func (Handler) GuardTransferSource(
	_ context.Context,
	_ format.Env,
	_ repo.Config,
	it model.Item,
) error

GuardTransferSource refuses, with 403, a copy or move whose source is a Xet record. Raw CAS records are read only through the native endpoint, whose capabilities recheck the caller (docs/testing/huggingface.md).

func (Handler) Reindex

func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error

Reindex reconstructs the native package/version view from committed snapshot files. A delete, restore or move cannot leave a stale revision.

func (Handler) Resolve

func (Handler) Resolve(
	_ context.Context,
	_ format.Env,
	_ repo.Config,
	d format.Download,
) (string, error)

Resolve refuses, with 403, a generic download of a Xet record, for the same reason as GuardTransferSource, and resolves any other path to itself.

type Identity

type Identity struct {
	Kind, Owner, Name string
}

Identity is one model or dataset in the current ML layout.

func ParseIdentity

func ParseIdentity(kind, owner, name string) (Identity, bool)

ParseIdentity accepts the names documented for Artifactory's Hugging Face repositories. A model and a dataset with the same Hub ID stay disjoint.

func ParseRefPath

func ParseRefPath(path string) (Identity, string, bool)

ParseRefPath reads path as a named ref's item path, the inverse of RefPath, and returns its identity and ref name. ok is false for any other path, and for an identity or a name that ParseIdentity or RefPath refuses.

func ParseSnapshotPath

func ParseSnapshotPath(p string) (Identity, string, string, bool)

ParseSnapshotPath is shared by the format hook, native client routes and lifecycle reindex. It never accepts the superseded legacy layout.

func (Identity) Prefix

func (id Identity) Prefix() string

Prefix is the identity's top-level folder in the current layout, <kind>--<owner>--<name>, which holds its snapshots, refs and Xet records. The kind is part of it, so a model and a dataset with one Hub ID never share a folder.

func (Identity) RepoID

func (id Identity) RepoID() string

RepoID is the identity's Hub repository ID, <owner>/<name>, as the client sends it; the kind is not part of it.

Directories

Path Synopsis
Package huggingfacehttp serves the native Hugging Face Hub client protocol for model and dataset repositories using Artifactory's current ML layout, under /artifactory/api/huggingfaceml/{repoKey}: the Hub API (repository info and trees by revision, repository and branch creation, preupload and commit), resolve downloads, Git LFS batch and signed uploads, the opt-in Xet tokens and CAS routes, and an administrator's bounded migration of a legacy revision into the current layout.
Package huggingfacehttp serves the native Hugging Face Hub client protocol for model and dataset repositories using Artifactory's current ML layout, under /artifactory/api/huggingfaceml/{repoKey}: the Hub API (repository info and trees by revision, repository and branch creation, preupload and commit), resolve downloads, Git LFS batch and signed uploads, the opt-in Xet tokens and CAS routes, and an administrator's bounded migration of a legacy revision into the current layout.
Package xet validates the public Hugging Face Xet chunk and shard wire formats: a xorb (a run of chunks, each optionally LZ4-compressed, with an optional footer of chunk hashes and boundaries) and a version-2 shard (the files an upload adds, each mapped to xorb chunk ranges, and the xorbs it claims).
Package xet validates the public Hugging Face Xet chunk and shard wire formats: a xorb (a run of chunks, each optionally LZ4-compressed, with an optional footer of chunk hashes and boundaries) and a version-2 shard (the files an upload adds, each mapped to xorb chunk ranges, and the xorbs it claims).

Jump to

Keyboard shortcuts

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