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
A detailed example of creating a custom model is available in the Training a Custom Model tutorial.
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 modelconfigure_optimizers()
: how optimizers should be configured in the modelcreate_model()
: gets the size of input data and initialises the model appropriatelyforward()
: how to perform a forward pass in the model, how the loss is calculatedtraining_step()
: what one training step in the model looks likevalidation_step()
: what one validation step in the model looks liketest_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.
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:
- In the Hub, go to My Models, then click the card for the model you wish to apply.
- Click the "Request Access" button.
- Specify the Pod you wish to use the model against and your purpose for using the model.
- Confirm the "Specific custom model(s)" at the bottom of the permissions section includes your desired model(s).
- 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
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=...)