Skip to main content

hub_model_resource

Concrete ModelResourceProtocol backed by the Bitfount Hub.

This module provides HubModelResource, a lightweight adapter that satisfies ModelResourceProtocol by downloading model code (and optionally weights) from the Bitfount Hub at inference time.

Module​

Functions​

model_load_timer_name​

def model_load_timer_name(base: str, model_ref: str) ‑> str:

Return the timer name for load phase base as measured for model_ref.

get_timer pools samples by name across every caller, and a task loads models whose sizes differ by an order of magnitude. Qualifying by the model keeps their distributions apart; the set of names is bounded by the models the task declares.

Arguments

  • base: One of the MODEL_LOAD_*_TIMER_NAME constants.
  • model_ref: Name of the model the phase was measured against.

Classes​

HubModelResource​

class HubModelResource(hub: BitfountHub, project_id: str | None = None):

Loads models from the Bitfount Hub for inference.

Implements ModelResourceProtocol.

Arguments

  • hub: An authenticated BitfountHub instance.
  • project_id: The project ID gating model access (may be None for publicly accessible models).

Methods​


load_model​

def load_model(    self,    model_ref: ModelInferenceConfig,    *,    datastructure: DataStructure,    schema: BitfountSchema,    batch_size: int | None,) ‑> ModelProtocol:

Download and instantiate a model from the Hub.

The model class and its weights are downloaded once per process and reused by every later wave, so all but the first call are local. The cached weights are encrypted on disk and decrypted here per wave. The model object itself is not reused: it is rebuilt here and the weights loaded into it, which keeps each wave's model state its own.

Arguments

  • model_ref: The ModelInferenceConfig identifying the model (its model_ref, model_version and model_username).
  • datastructure: DataStructure for model initialisation.
  • schema: BitfountSchema for model initialisation.
  • batch_size: Batch size hint (passed to model constructor if supported).

Returns An instantiated model ready for inference.