torchnative
Guide가이드

Test-time adaptation테스트 타임 적응

A model that ships to a device meets data its training set never had. Let it adapt in place, and be able to take it back.

기기로 간 모델은 학습 데이터에 없던 데이터를 만납니다. 제자리에서 적응하게 하고, 언제든 되돌릴 수 있게 합니다.

Wrap, serve, revert감싸고, 서빙하고, 되돌리기

from torchnative import adapt

model = adapt.wrap(model, method=adapt.Tent(), lr=1e-3)
model.online()      # adapt as it serves
...
model.revert()      # the base weights are back, byte for byte

Tent minimises prediction entropy over the normalisation weights. On SmolLM2-135M, ten steps took entropy on unlabelled text from 4.1604 to 2.9828, and a held-out sentence fell from 3.7237 to 2.9439, agreeing with upstream's own autograd to a median relative 1.5e-06.

Tent 는 정규화 가중치에 대해 예측 엔트로피를 최소화합니다. SmolLM2-135M 에서 열 스텝이 레이블 없는 텍스트의 엔트로피를 4.1604 에서 2.9828 로, 한 번도 적응에 쓰지 않은 문장을 3.7237 에서 2.9439 로 낮췄고, upstream autograd 와 중앙 상대오차 1.5e-06 으로 일치했습니다.

Two stages두 단계

Stage단계Needs backward역전파 필요Example예
0no아니오adapt.BatchNormStats(), re-estimate normalisation statisticsadapt.BatchNormStats(), 정규화 통계 재추정
1yes예adapt.Tent(), entropy minimisationadapt.Tent(), 엔트로피 최소화

A method declares only what it moves, what it descends and which stage it is. The delta owns everything else (revert, write and read back) so no method reimplements reset() or checkpointing.

방법은 무엇을 움직이고, 무엇을 내려가며, 어느 단계인지만 선언합니다. 나머지 (되돌리기, 쓰고 다시 읽기) 는 델타가 소유하므로 어떤 방법도 reset() 이나 체크포인팅을 다시 구현하지 않습니다.

The controls are part of the claim: the same loop with the sign flipped sends entropy up, lr=0 holds it to the last digit, and an objective on a detached tensor is refused by name. A loop that silently does nothing would pass any test that only checks it finished.

대조군도 주장의 일부입니다: 부호를 뒤집으면 엔트로피가 올라가고, lr=0 은 마지막 자리까지 그대로이며, 분리된 텐서 위의 목적함수는 이름으로 거부됩니다. 아무것도 안 하는 루프는 끝났는지만 보는 테스트를 모두 통과하기 때문입니다.