Skip to main content

model_reference

References to custom models.

Classes

BitfountModelReference

class BitfountModelReference(    model_ref: Union[Path, str],    datastructure: Optional[DataStructure] = None,    model_version: Optional[int] = None,    schema: Optional[BitfountSchema] = None,    username: Optional[str] = None,    hub: Optional[BitfountHub] = None,    hyperparameters: Optional[_StrAnyDict] = None,    private: bool = False,    new_version: bool = False,    secrets: Optional[Union[APIKeys, JWT]] = None,):

Describes a local or remote reference to a BitfountModel class.

tip

To use another user's custom model, simply provide that user's username instead of your own (along with the name of the model as the model_ref argument).

Arguments

  • datastructure: DataStructure to be passed to the model when initialised. This is an optional argument as it is only required for get_model to perform validation on the model before uploading it to the hub. Ensure that you provide this argument if you want to use get_model to upload your model.
  • hub: Required for upload/download of model. This attribute is set after initialisation on the worker side as the hub is not serialized. Defaults to None.
  • hyperparameters: Hyperparameters to be passed to the model constructor after it has been loaded from file or hub. Defaults to None.
  • model_ref: Either path to model file or name of model on hub.
  • model_version: The version of the model you wish to use. Defaults to the latest version.
  • new_version: Whether to upload a new version of the model to the hub. Defaults to False.
  • private: Boolean flag to set the model to be private to control useage or publicly accessible to all users.
  • schema: The BitfountSchema object associated with the datasource on which the model will be trained on.
  • secrets: The secrets to use when creating a BitfountHub instance. Defaults to None.
  • username: The username of the model owner. Defaults to bitfount session username if not provided.

Attributes

  • fields_dict: A dictionary mapping all attributes that will be serialized in the class to their marshamllow field type. (e.g. fields_dict = {"class_name": fields.Str()}).
  • nested_fields: A dictionary mapping all nested attributes to a registry that contains class names mapped to the respective classes. (e.g. nested_fields = {"datastructure": datastructure.registry})

Raises

  • ValueError: If username is not provided and hub is not provided.

Ancestors

  • bitfount.models.base_models._BaseModelRegistryMixIn
  • bitfount.types._BaseSerializableObjectMixIn

Variables

  • static nested_fields : ClassVar[Dict[str, Mapping[str, Any]]]

Methods


get_model

def get_model(self, project_id: Optional[str] = None)> Type[BitfountModel]:

Gets the model referenced.

If the model is a Path to a BitfountModel, it will upload it to BitfountHub and return the model class. If it is a name of a model on the hub, it will download the model from the hub and return the model class.

Returns The model class.

Raises

  • TypeError: If the model is not a Path or a string.
  • TypeError: If the model does not implement DistributedModelProtocol.
  • ValueError: If a BitfountHub instance has not been provided or if there was a communication error with the hub.
  • ValueError: If a datastructure has not been provided.

get_weights

def get_weights(self, project_id: Optional[str] = None)> Optional[bytes]:

Gets weights file uploaded for the model if one exists.

Returns The weights file as a byte stream.

send_weights

def send_weights(self, pretrained_file: Union[Path, str])> None:

Sends the model weights from a pretrained file to Hub.

Arguments

  • pretrained_file: The path to the pretrained model file.

Raises

  • ValueError: If model_version has not been set on BitfountModelReference instance.