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 ¶
- Decision 0032: docs/research/decisions/0032-package-format-handlers.md (the format hooks; the protocol and storage decision); decision 0007: docs/research/decisions/0007-remote-repositories.md (remote repositories).
- docs/testing/huggingface.md (connecting the Hub client, the layout, Xet and the evidence) and docs/operations/huggingface-migration.md (the legacy layout migration).
- JFrog Hugging Face repositories: https://docs.jfrog.com/artifactory/docs/hugging-face-repositories.
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 233 (ecosystem/huggingface), line 383 (package type huggingfaceml) and line 1006 (the mapping row).
- Plan: docs/implementation/plan.md#p32-data-and-model-repositories and #p9d-modular-monolith-migration, epic ECO (https://github.com/weaveplatform/artifactweave/issues/943).
- https://github.com/weaveplatform/artifactweave/issues/779 and https://github.com/weaveplatform/artifactweave/issues/1036
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 ¶
- func DeferReindex(ctx context.Context) context.Context
- func FilePath(s string) bool
- func IsXetPath(path string) bool
- func RefName(s string) bool
- func RefPath(id Identity, name string) (string, bool)
- func Revision(s string) bool
- func Serves(t repo.PackageType) bool
- func SnapshotPath(id Identity, revision, file string) (string, bool)
- func ValidXetPath(path string) bool
- func XetWrite(ctx context.Context) context.Context
- type Handler
- func (Handler) Admit(ctx context.Context, _ format.Env, c repo.Config, w format.Write) (format.Write, error)
- func (Handler) Classify(_ repo.Config, path string) format.Class
- func (h Handler) Deleted(ctx context.Context, env format.Env, c repo.Config, removed []model.Item) error
- func (Handler) Deleting(context.Context, format.Env, repo.Config, model.Item) error
- func (h Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it model.Item) error
- func (Handler) GuardTransferSource(_ context.Context, _ format.Env, _ repo.Config, it model.Item) error
- func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error
- func (Handler) Resolve(_ context.Context, _ format.Env, _ repo.Config, d format.Download) (string, error)
- type Identity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeferReindex ¶
DeferReindex lets a native multi-file commit publish its snapshot before rebuilding the package index once inside the same transaction.
func FilePath ¶
FilePath refuses traversal and control characters while preserving valid Unicode filenames used by model repositories.
func IsXetPath ¶
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 ¶
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 ¶
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 ¶
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 ¶
SnapshotPath returns the canonical item path for one file.
func ValidXetPath ¶
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).
Types ¶
type 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 ¶
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 ¶
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).
type Identity ¶
type Identity struct {
Kind, Owner, Name string
}
Identity is one model or dataset in the current ML layout.
func ParseIdentity ¶
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 ¶
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 ¶
ParseSnapshotPath is shared by the format hook, native client routes and lifecycle reindex. It never accepts the superseded legacy layout.
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). |