julia-model-deployment
Skill0 starsChanged 3 days agoMITView on GitHub
Deploy Julia models with JLD2, ONNX, PackageCompiler.jl, Genie.jl, Oxygen.jl, and PythonCall.jl. Use for Julia model export, API serving, containers, and startup latency.
In this repository55 other files it gives its agents.
- advanced-optimizationSkill
- bayesian-inferenceSkill
- bayesian-pinnSkill
- bayesian-ude-workflowSkill
- catalyst-reactionsSkill
- continuum-mechanics-and-rheologySkill
- control-theorySkill
- creating-julia-appSkill
- debugging-toolkitSkill
- differential-equationsSkill
- differentiationSkill
- equation-discoverySkill
- experiment-trackingSkill
- fem-feaSkill
- julia-graph-neural-networksSkill
- julia-languageSkill
- julia-ml-and-dlSkill
- julia-paper-implementationSkill
- julia-pro-helpSkill
- julia-pro-modeSkill
- julia-reinforcement-learningSkill
- modeling-toolkitSkill
- neural-pdeSkill
- nonlinear-dynamicsSkill
- numerical-methods-implementationSkill
- package-development-workflowSkill
- performance-tuningSkill
- physical-learning-systemsSkill
- playbook-debugSkill
- playbook-model-validateSkill
- playbook-package-releaseSkill
- playbook-paper-implementSkill
- playbook-perfSkill
- playbook-test-specSkill
- principle-both-sidesSkill
- principle-breakingSkill
- principle-file-is-truthSkill
- principle-gateSkill
- principle-limitsSkill
- principle-loud-failureSkill
- principle-one-stepSkill
- principle-proof-listSkill
- principle-rebuttalSkill
- principle-runtime-surfaceSkill
- principle-three-boundsSkill
- principle-three-clocksSkill
- scientific-visualizationSkill
- sciml-and-diffeqSkill
- setup-julia-proSkill
- signal-processingSkill
- simulation-and-hpcSkill
- statistical-physicsSkill
- symbolic-mathSkill
- web-development-juliaSkill
- zarr-cloud-arraysSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 128
Run with the system image:
- Distinctive: line 189
When the serving stack is Julia and a Python library has to be reached, use PythonCall.jl:
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Julia Model Deployment
Model Serialization with JLD2
Save and load trained model parameters:
using JLD2, Lux
model = Chain(Dense(784, 256, relu), Dense(256, 10))
ps, st = Lux.setup(Random.default_rng(), model)
# Train model...
# Save
jldsave("model.jld2"; ps=ps, st=st)
# Load
saved = load("model.jld2")
ps_loaded = saved["ps"]
st_loaded = saved["st"]ONNX Export with ONNXRunTime
Export models for cross-platform inference:
using ONNXRunTime
# Load an ONNX model for inference
model = ONNXRunTime.load("model.onnx")
# Run inference
input = Dict("input" => randn(Float32, 784, 1))
output = model(input)To export Julia models to ONNX, trace through the model and serialize:
using Flux, ONNXExporter
flux_model = Chain(Dense(784, 256, relu), Dense(256, 10))
dummy_input = randn(Float32, 784, 1)
ONNXExporter.export_onnx("model.onnx", flux_model, dummy_input)Genie.jl REST API
Serve predictions via HTTP:
using Genie, Genie.Router, Genie.Renderer.Json
using JLD2, Lux
# Load model at startup
const MODEL = Chain(Dense(784, 256, relu), Dense(256, 10))
const PARAMS = load("model.jld2")
route("/predict", method=POST) do
payload = jsonpayload()
x = Float32.(payload["input"])
y, _ = MODEL(x, PARAMS["ps"], PARAMS["st"])
json(Dict("prediction" => Array(y)))
end
route("/health") do
json(Dict("status" => "healthy", "version" => "1.0.0"))
end
up(8080; async=false)Oxygen.jl Lightweight Alternative
Minimal API server for simple deployments:
using Oxygen, HTTP
@post "/predict" function(req::HTTP.Request)
data = json(req)
x = Float32.(data["input"])
y, _ = MODEL(x, PARAMS["ps"], PARAMS["st"])
return Dict("prediction" => Array(y))
end
@get "/health" function()
return Dict("status" => "healthy")
end
serve(; host="0.0.0.0", port=8080)PackageCompiler.jl System Image
Eliminate startup latency with a custom system image:
using PackageCompiler
# Create sysimage with precompiled packages
create_sysimage(
[:Lux, :Genie, :JLD2];
sysimage_path="serving.so",
precompile_execution_file="precompile_script.jl"
)The precompile script exercises key code paths:
# precompile_script.jl
using Lux, JLD2, Genie
model = Chain(Dense(10, 5, relu), Dense(5, 2))
ps, st = Lux.setup(Random.default_rng(), model)
x = randn(Float32, 10, 1)
model(x, ps, st)Run with the system image:
julia --sysimage=serving.so serve.jlStandalone Application
Build a fully standalone executable:
create_app(
".", # Source directory
"build/serve_app"; # Output directory
precompile_execution_file="precompile_script.jl",
force=true
)Docker Multi-Stage Build
# Stage 1: Build sysimage
FROM julia:1.11 AS builder
WORKDIR /app
COPY Project.toml Manifest.toml ./
RUN julia --project=. -e 'using Pkg; Pkg.instantiate()'
COPY . .
RUN julia --project=. -e '
using PackageCompiler
create_sysimage(
[:Lux, :Genie, :JLD2];
sysimage_path="serving.so",
precompile_execution_file="precompile_script.jl"
)'
# Stage 2: Runtime
FROM julia:1.11-slim
WORKDIR /app
COPY --from=builder /app/serving.so .
COPY --from=builder /app/serve.jl .
COPY --from=builder /app/model.jld2 .
EXPOSE 8080
HEALTHCHECK CMD curl -f http://localhost:8080/health || exit 1
CMD ["julia", "--sysimage=serving.so", "serve.jl"]Build and run:
docker build -t julia-model-server .
docker run -p 8080:8080 julia-model-serverCall Python from Julia
When the serving stack is Julia and a Python library has to be reached, use PythonCall.jl:
using PythonCall
np = pyimport("numpy")
flask = pyimport("flask")
# Bridge Julia inference into a Python web framework
function julia_predict(input_array)
x = pyconvert(Matrix{Float32}, input_array)
y, _ = MODEL(x, PARAMS["ps"], PARAMS["st"])
return Py(Array(y))
endLatency Optimization
| Strategy | Startup Time | Binary Size | Use Case |
| Default Julia | ~30s (TTFX) | N/A | Development |
| Sysimage | ~2s | ~500MB | Production servers |
| Standalone app | ~0.5s | ~1GB | Edge / containerized |
| PrecompileTools.jl | ~5s (cached) | N/A | Package development |
Production Checklist
- Serialize models with JLD2 (include both
psandst) - Add
/healthendpoint for load balancer probes - Build a sysimage to eliminate first-call latency
- Use multi-stage Docker builds to minimize image size
- Pin Julia version and
Manifest.tomlfor reproducibility - Add request validation and error handling middleware
- Set up structured logging (JSON format for log aggregators)
- Load test with realistic payloads before deploying
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

