Skip to main content
Stages 2 and 3 · Deploy and Key generation

Deploy the pipeline

Two stages live here. First you send the pipeline to the platform and compile it. Then you create an access token and generate keys. Deploy does not create a token or generate keys. After both stages finish, you can run queries.

Stage 2 · Deploy

Deploy is a single function, studio.deploy_pipeline. You give it the pipeline and parameters from the previous stage, plus a model_name. It returns a model_id for your deployed pipeline.
deploy.pyPYTHON
from lattica_studio import LatticaStudio

studio = LatticaStudio(license_key)

model_id = studio.deploy_pipeline(
    pipeline,
    params,
    "MY_MNIST_MODEL",
    display_graph=True,
)
What this wraps

deploy_pipeline is an envelope. It runs several steps for you: registering the model (or reusing one with the same name), uploading, and compiling. It does not issue an access token. The next section opens it up. If you want each step as its own call, the full sequence is in the platform documentation.

Calling deploy_pipeline again with the same model_name redeploys into that model: it stops any running workers, re-uploads, and recompiles. num_devices cannot change. Use a different name if you need a different device count.

What happens inside deploy

Three things happen when you deploy. You do not call them separately, but it helps to know what the platform and client are doing.
1
Register or reuse the modelon platform

If no model has this model_name, one is created. If one already exists, that model is reused: running workers are stopped, and the instance type can be updated. Device count cannot change.

2
Uploadto platform

Your pipeline and parameters are serialized and sent to the platform.

3
Compileon platform

The platform turns your pipeline into an FHE circuit it can run. This is the step that can fail if the pipeline and parameters do not fit. Deploy waits for it to finish.

What compilation tells you

When compilation fails

Compile is the step that depends on your work. If the pipeline is too deep for its parameters, or an operator is set up wrong, compilation does not pass. Deploy returns the error so you can fix it.
Two ways deploy can stop at compile
RuntimeErrorCompilation failed. The model goes inactive. Usually the pipeline and parameters do not fit, revisit your operators or your parameter levels.
TimeoutErrorCompilation ran past the time limit without finishing.
Both send you back to Build. Adjust the pipeline or parameters and deploy again.
A reference of compilation errors and how to resolve each one is in Compilation Errors.

When compilation passes

A compile that passes is also worth reading. It comes back with numbers: accuracy, expected query latency, and worker memory the pipeline claims. A pipeline can be correct and still miss on speed or size. This report is where you find out, before the worker starts and the credits do.

The compiler's report is one of three instruments the platform gives you. The full map (debugger, printed graph, and this report) is in Inspecting the pipeline.

What you have after deploy

When deploy finishes cleanly, two things are in place. An access token and keys are not. Those come next, in Key generation.
model_id
Your deployed pipeline. You start its worker with this.
Compiled pipeline
On the platform, ready for a worker. Create a token and generate keys before you query.

Stage 3 · Key generation

After compile, create a query token and generate keys. This stage is one-time per compiled pipeline. Later query runs reuse the same token and key context.
1
Create access tokenon client

Call studio.tokens.create(model_id, save_as=model_name). The token is scoped to this deployment and written locally so you can load it later with studio.tokens.load.

2
Generate keys and register EKon client

Create a QueryClient with the token, then call generate_key(load_if_exists=False). The secret key stays on your machine. The evaluation key uploads and registers for later queries.

keygen.pyPYTHON
from lattica_query import QueryClient

token = studio.tokens.create(model_id, save_as="MY_MNIST_MODEL")
query_client = QueryClient(token)
query_client.generate_key(load_if_exists=False)
When this stage finishes, you have an access token on disk, key artifacts on disk, and an evaluation key registered for this model. Recurring queries load that context instead of generating it again.
Access token
Saved locally under this model_name. Authorizes your queries.
Keys
Secret key stays with you. Evaluation key is registered for the worker.

Next

Inspect

Inspecting the Pipeline

Print the graph locally and read the compiler report before you query.