bitfount_model
Contains the base classes for handling custom models.
Classes
BitfountModel
class BitfountModel( datastructure: DataStructure, schema: BitfountSchema, seed: Optional[int] = None, param_clipping: Optional[dict[str, int]] = None,):
Base class for custom models which must implement DistributedModelProtocol
.
A base tagging class to highlight custom models which are designed to be uploaded to Bitfount Hub.
Arguments
datastructure
:DataStructure
to be passed to the model when initialisedparam_clipping
: Arguments for clipping for BatchNorm parameters. Used for federated models with secure aggregation. It should contain the SecureShare variables and the number of workers in a dictionary, e.g.{"prime_q":13, "precision": 10**3,"num_workers":2}
. Defaults to None.schema
: TheBitfountSchema
object associated with the datasource on which the model will be trained on.seed
: Random number seed. Used for setting random seed for all libraries. Defaults to None.
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}
)
Ancestors
- bitfount.models.base_models._BaseModel
- bitfount.models.base_models._BaseModelRegistryMixIn
- bitfount.types._BaseSerializableObjectMixIn
- abc.ABC
- typing.Generic
Subclasses
Static methods
serialize_model_source_code
def serialize_model_source_code( filename: Union[str, os.PathLike], extra_imports: Optional[list[str]] = None,) ‑> None:
Serializes the source code of the model to file.
This is required so that the model source code can be uploaded to Bitfount Hub.
Arguments
filename
: The filename to save the source code to.extra_imports
: A list of extra import statements to include in the source code.