Deploy Whisper Large V3 using Inferless
OpenAI releases Whisper-large-v3, a pre-trained model for automatic speech recognition (ASR) and speech translation
Our Observations
We have deployed this model using A100 GPU and observed that the model took an average cold start time of 9.13sec
and an average inference time of 1.44sec
for an average audio length of 7.4sec
.
Defining Dependencies
We are using the HuggingFace Transformers library for the deployment.
Constructing the GitHub/GitLab Template
Now quickly construct the GitHub/GitLab template, this process is mandatory and make sure you don’t add any file named model.py
Whisper-large-v3/
├── app.py
└── config.yaml
You can also add other files to this directory.
Create the class for inference
In the app.py we will define the class and import all the required functions
def initialize
: In this function, you will initialize your model and define anyvariable
that you want to use during inference.
class InferlessPythonModel:
def initialize(self):
self.generator = pipeline(
"automatic-speech-recognition",
model="openai/whisper-large-v3", chunk_length_s=30, batch_size=8,
torch_dtype=torch.float16,
device_map="cuda:0",
)
def infer
: This function gets called for every request that you send. Here you can define all the steps that are required for the inference. You can also pass custom values for inference through theinputs
parameter.
def infer(self, inputs):
audio_url = inputs["audio_url"]
pipeline_output = self.generator(audio_url, )
return {"transcribed_output": pipeline_output["text"] }
def finalize
: This function cleans up all the allocated memory.
def finalize(self,*args):
self.generator = None
Creating the Custom Runtime
This is a mandatory step where we allow the users to upload their own custom runtime through config.yaml.
build:
system_packages:
- "ffmpeg"
python_packages:
- "ffmpeg-python"
- "ffmpeg"
- "torch==2.1.0"
- "transformers==4.36.1"
Deploying the model on Inferless
Inferless supports multiple ways of importing your model. For this tutorial, we will use GitHub.
Import the Model through GitHub
Click on theRepo(Custom code)
and then click on the Add provider
to connect to your GitHub account. Once your account integration is completed, click on your Github account and continue.
Provide the Model details
Enter the name of the model and pass the GitHub repository URL.
Now, you can define the model’s input and output parameters in JSON format. For more information, go through this page.
-
INPUT: Refer to the function
def infer(self, inputs)
, here we mentionedinputs["audio_url"]
, which meansinputs
the parameter will have a keyaudio_url
. -
OUTPUT: The same goes here, the function mentioned above will return the results as a key-value pair return
{"transcribed_output": pipeline_output["text"]}
.
Input JSON must include audio_url
a key to pass the instruction. For output JSON, it must be included transcribed_output
to retrieve the output.
GPU Selection
On the Inferless platform, we support all the GPUs. For this tutorial, we recommend using A100 GPU. Select A100 from the drop-down menu in the GPU Type.
Using the Custom Runtime
In the Advance configuration
, we have the option to select the custom runtime. First, click on the Add runtime
to upload the config.yaml file, give any name and save it. Choose the runtime from the drop-down menu and then click on continue.
Review and Deploy
In this final stage, carefully review all modifications. Once you’ve examined all changes, proceed to deploy the model by clicking the Import
button.
Voilà, your model is now deployed!