﻿# PatchTST RevIN ports: normalization statistics belong to the matching inference call

Preserve PatchTST reversible instance normalization statistics, affine parameters and normalization/denormalization pairing when separating or parallelizing execution stages.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-patchtst-revin-instance-statistics-paired-denormalization/
Language: en

## Identify the normalization boundary

The original PatchTST supervised implementation can apply reversible instance normalization around its forecasting backbone. The [model wrapper](https://raw.githubusercontent.com/yuqinie98/PatchTST/main/PatchTST_supervised/models/PatchTST.py) configures this behavior. It is not simply a dataset-wide scaler fitted once and reused for every input. A port should identify which quantities are computed from the current history and which parameters belong to the trained model, because those states require different handling during export or concurrent execution.

## Follow current-history statistics

The [RevIN implementation](https://raw.githubusercontent.com/yuqinie98/PatchTST/main/PatchTST_supervised/layers/RevIN.py) computes context statistics and retains them for the corresponding inverse operation. Depending on configuration, centering uses a mean or the last observed position, while scale comes from context variance. These statistics describe the current input instance. They should not be borrowed from another request or treated as immutable checkpoint parameters merely because the reference Python module stores them as attributes.

## Preserve learned affine behavior separately

Optional affine weights and biases are learned model parameters, unlike the context-derived location and scale. The inverse path reverses the affine transformation before restoring the input's scale and center. Dropping those steps can change output units even if normalized network predictions match. The [backbone implementation](https://raw.githubusercontent.com/yuqinie98/PatchTST/main/PatchTST_supervised/layers/PatchTST_backbone.py) pairs normalization and denormalization within its forward path. Preserve that ordering rather than independently composing similarly named utilities.

## Keep state paired when execution is split

A serving port may separate preprocessing, accelerator execution and output restoration. Carry the correct per-input statistics through those stages explicitly. Interleaving a second normalization before the first result is restored must not substitute the second input's state. The [TinyTimeMixer preprocessing guide](/journal/fg2-tinytimemixer-preprocessor-training-group-scaler-state/) provides a contrasting fitted-scaler boundary. This is a porting requirement, not a claim that every ordinary reference forward call has a concurrency defect.

## Test units and request separation

Use histories with deliberately different centers and scales, and compare batched or interleaved stage execution against independently completed reference forwards. Verify affine-enabled and configured centering modes. The [artifact-manifest guide](/journal/tokenizer-artifact-release-manifest/) supplies release context. A correct port preserves the normalized computation and restores each result to its own measurement unit, separating immutable model weights, per-input numerical state and the scheduling policy used to execute the network.
