BB.Inference.Artefact.Placement (bb_inference v0.1.0)

Copy Markdown View Source

Fetches model artefacts and places them under a priv directory. Used by Mix.Tasks.Compile.BbInference, which supplies the directories.

The cache

URL sources are downloaded once into a cache outside the project, keyed by the URL's own SHA-256, and reused by every project and every build that declares the same URL. An archive is cached whole and the member extracted from it each time it is placed.

Outcomes

  • Placed - the artefact is in priv and, where a sha256 is declared, matches it.
  • Warning - the download failed. Nothing is placed and nothing is recorded, so the next build tries again.
  • Error - the artefact doesn't match its declared sha256, the local source doesn't exist, or the archive doesn't contain the member. A download that doesn't match is deleted from the cache, so the next build downloads it again rather than failing on the same bytes.

Not re-hashing

The manifest records, for each placed artefact, what was declared and the size and modification time of the file placed. An artefact whose declaration and file are both unchanged is not hashed again.

Summary

Functions

Place every artefact, returning what was said about each and the new manifest.

Types

artefact()

@type artefact() :: %{
  model: atom(),
  source: String.t(),
  archive_member: String.t() | nil,
  sha256: String.t() | nil,
  path: Path.t()
}

diagnostic()

@type diagnostic() :: {:warning | :error, String.t()}

manifest()

@type manifest() :: %{required(Path.t()) => term()}

options()

@type options() :: [
  priv_dir: Path.t(),
  cache_dir: Path.t(),
  manifest: manifest(),
  info: (String.t() -> any())
]

Functions

place_all(artefacts, opts)

@spec place_all([{module(), artefact()}], options()) :: {[diagnostic()], manifest()}

Place every artefact, returning what was said about each and the new manifest.

Files under priv_dir that the old manifest placed and that no artefact now declares are removed.