Skip to main content

Custom Models

Custom models require an additional level of permissions because they can be defined as arbitrary code. To use a custom model, you will need to first ensure you have the required permissions and then run the model using the BitfountModelReference class.

Defining Custom Models

tip

A detailed example of creating a custom model is available in the Training a Custom Model tutorial.

caution

Saving a custom model to Bitfount currently does not mean the model is private. Any model a Data Scientist saves to the Hub is accessible via its hub.bitfount.com URL, so be sure you are comfortable with your model architecture being publicly accessible prior to upload.

To define a custom model, you need to create a class that inherits from the PyTorchBitfountModel class and implement the following methods:

  • __init__(): how to set up the model
  • configure_optimizers(): how optimizers should be configured in the model
  • create_model(): gets the size of input data and initialises the model appropriately
  • forward(): how to perform a forward pass in the model, how the loss is calculated
  • training_step(): what one training step in the model looks like
  • validation_step(): what one validation step in the model looks like
  • test_step(): what one test step in the model looks like

Once you’ve saved the file, navigate to the My Models page on Bitfount Hub. Here you can upload your file for future use.

Permissions

To use a custom model with a Pod you need to either be granted the:

  • Super Modeller role, which means that you can run arbitrary code; or
  • General Modeller role, along with the specific permission to use the chosen Custom Model.
danger

Bitfount does not vet the contents of custom models. Granting the Super Modeller role means the Data Scientist can execute any code on the specified Pod.

If you do not have the required permissions, ask the Pod owner to authorise custom models using the instructions in the Authorising Pods guide.

If you already have visibility on a Pod, you can request to use a given model for a specific Pod:

  1. In the Hub, go to My Models, then click the card for the model you wish to apply.
  2. Click the "Request Access" button.
  3. Specify the Pod you wish to use the model against and your purpose for using the model.
  4. Confirm the "Specific custom model(s)" at the bottom of the permissions section includes your desired model(s).
  5. Click "Request Access"

Once submitted, the Pod owner will receive an access request in their Hub view and will be able to review your model contents and grant or reject the access request.

Running Custom Models

tip

A detailed example of running a custom model is available in the Training a Custom Model tutorial.

To run a custom model, you need to instantiate it as a BitfountModelReference. The api for this model follows much the same as for other models.

model = BitfountModelReference(
username="INSERT USERNAME",
model_ref="MyCustomModel",
datastructure=datastructure,
schema=schema,
model_version=1, # NOTE: this uses a specific version of the model (default is latest uploaded),
hyperparameters={"epochs": 2},
)
model.fit(pod_identifiers=...)