ML model conversion to ONNX — optimization for deployment

The model works in the development environment but loses speed under real load? We convert models to a unified format and set up inference turnkey: we transfer without retraining, accelerate response times by multiples, and hand the team a ready-to-use launch scheme.
Frequently Asked Questions

Why converting a model to ONNX breaks inference

A trained model lives inside a single environment, while inference needs a portable artifact that computes identically on a server, in an embedded environment, and in a browser.

Converting a model to ONNX is not re-saving a file but rebuilding the computational graph for a different set of operators. Therefore, moving a model to a single format almost always reveals discrepancies that were invisible inside the original environment.

The first class of failures is a discrepancy in results after transfer.

Some operators in the original environment are computed with accumulation in extended precision, while in the target execution they are computed in single precision; convolutional layers and normalization collapse into different formulas.

Externally the graph is valid, the output tensor has the same shape, but a discrepancy of tenths of a percent accumulates across layers and over a long chain changes the final decision.

The second is unsupported model layers and a graph export error. Tracing does not transfer custom layers and data-dependent branches: it fixes one execution path and silently loses the others.

The same effect comes from the choice of operator set — an operator from a new branch is absent from the old set, and the exporter either fails or substitutes it with an approximation.

The third is a mismatch in input preprocessing. Resize with a different interpolation filter, channel order, normalization range, and input type produce a shift that is easily mistaken for an error in the model itself. We break down how this is closed.

What changes after converting a model to a single format

Converting a model to a single format breaks the link between the inference service and the training library. The ONNX computational graph describes only what is needed for a run: operators, input shapes, weights.

The heavy training environment leaves the container, so the model's cold start time drops from tens of seconds to units — the replica has time to come up before traffic arrives, not after.

The model artifact size falls severalfold: weights are stored in half precision or quantized, and layers not involved in inference are cut during conversion. A smaller artifact means faster image rollout across nodes and less disk for caching previous versions.

Service load predictability grows from the fixed graph: static input shapes, fused operations, known memory consumption. At peak, the service hits the limit of replica count, not unpredictable resource consumption for parsing dynamic layers.

A model update becomes a normal artifact release. The file carries metadata — input names, tensor shape, version — compatibility is checked before rollout, and rollback is reduced to file replacement.

The share of failures during updates falls: the version desync between library and environment, which previously surfaced only in production, disappears.

The limitation is honest: not all operators convert one-to-one.

For custom layers we write an implementation for the target execution environment, and we verify the numerical result against the original model on a reference input set — a discrepancy above tolerance blocks the release. This verification is what gives the model release stability visible in metrics.

Transfer modes and formats: comparison of approaches

Putting a model into production is not one command but a choice among four schemes: from a unified intermediate format to a build for a specific server.

Below is a comparison by where each scheme wins and what it costs — with the same input model, the difference in behavior and support cost is noticeable.

Option When suitable Limitations
Unified intermediate format (ONNX) Multiple execution environments: server, client browser, embedded device Some non-standard layers are not expressed by the standard operator set — a fallback path to the original environment is needed
Custom build for server One target server and a fixed execution environment Hard binding to configuration: updating the environment or moving to other hardware means a rebuild and re-validation
Optimization for specific hardware Response latency is critical, load is consistently high Compression and layer fusion shift predictions: calibration on real data and control of quality metrics are needed
Hybrid inference mode Traffic peaks and a heterogeneous fleet of devices Two artifacts instead of one: versions diverge if you do not keep a common weight source and an automated test for output match

We choose based on operating conditions, not format fashion: first we fix where the model will run and what quality metrics cannot be lost, then we calculate the allowable load.

In practice, hybrid mode gives a 2-3x speedup at peaks while preserving the base branch accuracy for the rest of the traffic.

Stages of work: from graph audit to handover

We structure the work so that current releases do not stop: the transfer goes in iterations, and the result of each step is checked. Below is the path from model inventory to handover to your team.

  1. Model inventory. Collect what goes to production: what they were trained on, inputs and outputs, retraining frequency, response latency requirements. Mark what to transfer first and what can wait.

  2. Computational graph audit. Parse the graph by nodes: non-standard layers, dynamic axes, postprocessing inside the model itself. Everything without a direct analog in the target format is marked — this is the scope of modifications.

  3. Model transfer scheme. Fix what transfers as is, what is replaced by an equivalent operator, and what goes into application code. Agree on computation precision and allowable output discrepancy.

  4. Model artifact assembly. Prepare the graph, input/output configuration, dictionaries and preprocessing rules, and version them together with the weights. The rebuild is reproducible with one command, without manual edits.

  5. Result match verification. Run the original and transferred model on the same dataset, compare outputs by metric and by discrepancy on individual predictions. Exceeding the threshold returns us to the graph audit, not to release.

  6. Handover of the solution to the team. Give the artifacts, rebuild scripts, transfer scheme description, and procedure for adding new models, and train your engineers. Stay in touch during the first releases.

What remains with you after work completion

The work ends not with a demo but with a repository state you can return to in six months and repeat the transfer without us. Below is what exactly remains with you and what task each unit closes.

  • Model build configurations — export parameters, list of supported operators, fixed input dimensions. Rebuilding from these files yields the same artifact, not a "roughly similar" one.
  • Data preprocessing scheme — normalization order, type casting, handling missing and extreme values. It describes how a raw request turns into model input and matches what was actually validated during transfer.
  • Model access policies — roles for publishing and reading artifacts in storage, rules for issuing keys on the execution side. Access revocation does not require a model rebuild.
  • Repeat transfer procedure — a step-by-step route for an updated version: from fixing weights to running checks. An engineer from your team follows it independently.
  • Test sets for verification — reference inputs with expected outputs and allowable discrepancy. They also serve as the basis for acceptance and for analyzing regressions in the future.
  • Verification report — metric discrepancy between the original and transferred model on a control sample, indicating the layers where tolerance is exceeded.

Each item is a working file in the repository, not text in a presentation: it can be opened, modified, and run. The handover is considered complete when your team independently assembles the model, runs the checks, and publishes a new version.

Case: accelerated model inference without retraining

A document recognition service ran on four nodes, and for each one its own model version was built: different library versions, different environments, different preprocessing.

Release took days, and model behavior on the same request differed from node to node — reproducing the error outside production was not always possible.

What changed

We exported the trained model to a single ONNX graph — an open format executed identically on any platform and not pulling a training stack with it.

Inputs and outputs were fixed explicitly, layers tied to a specific library were removed, and one artifact was assembled instead of four builds.

Before release we ran a reference set of requests and compared responses with the original model: the discrepancy stayed within fractions of a percent, and disputed cases were reviewed manually.

What became

Now all nodes have the same model file — deployment reduced to artifact delivery and service restart, and rollback to the previous version takes minutes. Median response reduced roughly by half, and the latency tail on heavy requests fell by a third.

The share of timeout failures fell from six percent to one, while answer accuracy remained at the same level: the model is the same, only the method of execution changed.

What to do if the model is already built in another format

When a trained model is already in production, retraining is usually unavailable: the training dataset may have been deleted, data preparation is not reproduced accurately, and the artifact itself is tied to a specific environment.

Therefore transfer to ONNX is not retraining but moving already obtained weights to another graph format: the values remain the same, only the execution method changes.

The first thing checked is the existing artifact. The weight checksum is fixed to later confirm that this exact version was transferred, and the input and output tensors are described: size, axis order, data type.

Separately, preprocessing is restored — normalization, channel order, value scale: in practice the discrepancy after conversion arises here, not in the graph itself.

Then reference responses are captured: the original model is run on a control set of examples and the outputs are saved.

This is the only basis for comparison, and it can only be obtained before conversion — after it, distinguishing a transfer error from an old model error is no longer possible.

Export is performed with training mode disabled, fixed input shapes, and operation fusion to remove extra recomputations.

Then the outputs are compared: the share of matching responses on the control set must remain the same, and the numerical discrepancy must be within tolerance.

If some operations are unsupported by the target environment, they are rewritten pointwise without affecting the rest of the graph.

The transition is done without stopping the service: the new artifact is raised next to the old one, first in shadow mode where it processes a copy of live traffic, and discrepancies are logged.

When the match is confirmed, the traffic share is increased gradually, leaving the previous version available for instant rollback with one configuration change.

The key here is not training quality but compatibility and version control. The weights do not change, so the risk is concentrated in preprocessing, tensor shapes, and the switching method.

Technical doubts around ONNX and engineers' answers

Moving a model to ONNX is changing the computational graph format, not retraining: the weights stay the same, only the method of executing them on a server or device changes. Below are five questions most often asked at this stage, with substantive answers.

We conduct the transfer as a task with a verifiable result: we predefine the reference input set and allowable metric deviation, and the solution goes into operation only after the outputs match.

Will accuracy be lost after transfer?

Deviation is caused not by the format itself but by rounding and computation order in the execution environment. We compare the outputs of both models on the same input set and keep the discrepancy within bounds that do not change the final decision.

What to do with layers absent from the standard set?

Such operations are mapped manually: some decompose into an equivalent combination of supported ones, and for others we write our own operator. If a layer is tied to a rare library, we assess whether to rewrite it or leave it as a separate block.

Will the model have to be retrained?

No. Transfer does not change the weights and does not require new data — otherwise quality would shift and re-validation would be needed. Retraining is needed only if you yourself change the architecture for device requirements.

How to make sure outputs match?

Prepare a reference input set, including edge cases, run both models, and compare outputs elementwise. Additionally, check the metric on a holdout sample — it shows whether the result remained in the previous quality class.

Can we return to the original format?

Yes, reverse transfer is possible. But we do not rely on it: the original weights, training configuration, and export script are stored in the model repository, so rollback takes minutes rather than turning into restoration from memory.

Let's discuss your model transfer task

To make the estimate of transfer work realistic and the model transfer timelines feasible, we need inputs on the model and on the environment where it will go. Below is the minimum set usually enough to calculate labor costs by stages, not "by feel".

  • Architecture and purpose: what is input and output, data shapes, whether there are dynamic axes and graph branches.
  • Model weight and the library it was trained in — this determines whether an intermediate representation is needed when converting to ONNX.
  • Target environment: CPU or accelerator, operating system, execution environment, and set of computational operators.
  • Requirements for response time and number of concurrent requests per instance — based on them we choose computation precision and depth of graph optimization.
  • Preprocessing and postprocessing chain: normalization, resizing, output decoding — we also transfer and verify it separately.
  • Test input set with reference answers: 50–100 examples are enough to compare quality before and after transfer.
  • Access restrictions: deploy in a public cloud or a closed segment without external access.

Based on this data we see where standard operators suffice and where own ones must be written, and we assemble a transfer work plan: stages, intermediate checkpoints, team composition for the task — machine learning engineer, execution environment specialist, QA engineer.

We will return with an estimate by each stage, model transfer timelines, and a list of risks affecting the launch date. Describe the task and attach what you have — we will return with a plan and clarifying questions.

AI Development Areas

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1393
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1368
  • B2B Advance company logo design
    B2B Advance company logo design
    815
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1139
  • AIDER company logo development
    AIDER company logo development
    1057
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1152