CLI app provides functionality to deploy custom models onto fma infrastructure. It employs features of pydantic library extended with custom field types to describe model's io. It interacts with fma services to send your models code and to run it on fma's hardware.
You have to create a new folder and run fma init <your_model_name> inside of it.
This will create one more folder with your model name and a model.py file inside of it.
The model.py will be prepolutated with:
from typing import List
from pydantic import BaseModel
from fma.toolkit import model as fma_model
class Input(BaseModel):
pass
class Output(BaseModel):
pass
class Model(fma_model.Model):
requirements: List[str] = []
def initialize(self):
pass
def predict(self, input: Input) -> Output:
return {}IMPORTANT NOTE: even though io is described via pydantic models they are not actually supported in the predict method.
Instead predict method accepts and returns python dicts.
Support for pydantic models will be added eventually.
During this step you simply have to populate the initialize and predict methods with inferences logic.
You can set instance attributes via accessing self, all the imports should be inside of the methods.
You can also specify required libraries and packages in the requirements field of Model class.
If you have finished all the steps above all you need to do is to:
You can do this via fma login --username <username> --password <password>
or by providing one/none, missing ones will be prompted.
By running fma deploy
After this the data about your model will be written into metadata.yaml file.
Fields in input object also support default value declaration.
Example of Input class that uses default values:
class Input(BaseModel):
text: str = Field(default="Hello")
number: int = Field(default=1)
fraction: float
flag: bool = Field(default=True)
image: Image
file: File
audio: Audio
otext: Optional[str]
onumber: Optional[int] = Field(default=1)
ofraction: Optional[float] = Field(default=0.2)
oflag: Optional[bool] = Field(default=False)
oimage: Optional[Image]
ofile: Optional[File]
oaudio: Optional[Audio]
Currenly standard python str, int, bool, float are available.
The also can be used in combination with typing.Optional
You can specify audio, image and file fields in the io classes by:
from fma.toolkit.fields.audio import Audio
from fma.toolkit.fields.image import Image
from fma.toolkit.fields.file import File
Note that File is currently supported only as the output
You can delete the deployed model if you don't need it anymore:
fma delete
fma update will delete the model and redeploy it under the same name if available.
fma logs --output-file logs.tx will download logs into specified file or display them in stdout otherwise.