Autoscaler
PyWorker
Overview
7 min
the vast pyworker is a python web server designed to run alongside a machine learning model instance, providing autoscaler compatibility it serves as the primary entry point for api requests, forwarding them to the model's api hosted on the same instance additionally, it monitors performance metrics and estimates current workload, reporting these metrics to the autoscaler all of vast's autoscaler templates use the vast pyworker if you are using a recommended autoscaler template from vast, the pyworker is already integrated with the template and will automatically startup when a {{worker group}} is created pyworker diagram in the diagram's example, a user's client is attempting to infer from a machine learning model with vast's autoscaler setup, the client sends a /route/ post request to the autoscaler this asks the autoscaler for a gpu instance to send the inference request the autoscaler selects a ready and available worker instance from the user's endpoint and replies with a json object containing the url of the selected instance the client then constructs a new post request with it's payload, authentication data, and the url of the worker instance this is sent to the worker the pyworker running on that specific instance validates the request and extracts the payload it then sends the payload to the model inference server, which runs on the same instance as the pyworker the model generates it's output and returns the result to the pyworker the pyworker formats the model's response as needed, and sends the response back to the client independently and concurrently, the pyworker periodically sends it's operational metrics to the autoscaler, which the autoscaler uses to make scaling decisions the vast pyworker repository https //github com/vast ai/pyworker/ gives examples that are useful for learning how to create a custom pyworker for your custom template and integrate with vast’s autoscaling server even with a custom pyworker, the pyworker code runs on your vast instance, and we automate its installation and activation during instance creation the graphic below shows how the files and entities for the tgi (text generation inference) autoscaler from the pyworker repository are organized files and entites for the tgi autoscaler template integration with model instance the vast pyworker wraps the backend code of the model instance you are running the pyworker calls the appropriate backend function when the pyworker's corresponding api endpoint is invoked for example, if you are running a text generation inference (tgi) server, your pyworker might receive the following json body from a /generate endpoint json { "auth data" { "signature" "a base64 encoded signature string from route endpoint", "cost" 256, "endpoint" "your tgi endpoint name", "reqnum" 1234567890, "url" "http //worker ip address\ port" }, "payload" { "inputs" "what is the answer to the universe?", "parameters" { "max new tokens" 256, "temperature" 0 7, "top p" 0 9, "do sample" true } } } when it receives this request, your pyworker will internally send the following to the tgi model sever json { "inputs" "what is the answer to the universe?", "parameters" { "max new tokens" 256, "temperature" 0 7, "top p" 0 9, "do sample" true } } your pyworker would similarily receive the output result from the tgi server, and forward a formatted version to the client communication with autoscaler if you are building a custom pyworker for your own use case, to be able to integrate with vast's autoscaling service, each backend must send a message to the autoscaling server when the backend server is ready (e g , after model installation) periodically send performance metrics to the autoscaling server to optimize server usage and performance report any errors to the autoscaling server for example implementations, reference the vast pyworker repository creating a custom backend if you want to create your own backend and learn how to integrate with the autoscaling server, please refer to the following guides extension guide https //docs vast ai/serverless/creating new pyworkers vast supported backends vast has pre made templates for popular models such as t ext generation inference and comfy ui https //docs vast ai/serverless/comfy ui these templates allow you to use these models in api mode, automatically handling performance and error tracking, making them compatible with vast's autoscaler with no additional code required to get started with vast supported backends, see the pyworker backends guide https //docs vast ai/serverless/inside an autoscaler gpu