트레이스에서 회귀 찾아내기
읽는 데 약 31분, 7절에 7개 예제이(가) 있음.
AI로 번역함. 영어 원문을 사람이 검증함. 우리가 책을 만드는 방식
영어판 2026.11.2판을 번역한 것이다. 원문 읽기
Labs
직접 해 보며 이 장을 배운다
모든 예제를 책에서 한 그대로 실행하고, 코드를 바꿔 결과를 확인하며, 책의 코드와 데이터에 자신의 아이디어를 적용해 본다. 설치할 것은 없으며 작업 내용은 저장된다. 약 30초 안에 열린다.
모든 예제를 책에서 한 그대로 실행하고, 코드를 바꿔 결과를 확인하며, 책의 코드와 데이터에 자신의 아이디어를 적용해 본다. 설치할 것은 없으며 작업 내용은 저장된다. Labs가 실행을 대신한다: 월 40시간.
자신의 컴퓨터에서, 무료로: 이 책의 노트북 내려받기, 코드와 데이터를 포함해 GitHub에서 받을 수 있다.
책의 버전에서 코드 실행하기
이 장을 마치면 릴리스가 어떤 수치를 움직였는지, 얼마나 움직였는지, 그리고 그 변화가 그날의 잡음보다 큰지를 말할 수 있다. 릴리스가 너무 많이 움직이면 배포를 막는 규칙도 작성할 수 있다. 어시스턴트에 대한 네 가지 변경이 배포를 기다리고 있으며, 각각 중요한 것은 아무것도 바꾸지 않는다고 주장한다. 하나는 라우팅 프롬프트에 라우팅 예시 six개를 추가한다. 하나는 4B 모델인 Qwen3-4B-Instruct-2507을 더 작은 Qwen3-0.6B로 교체한다. 하나는 검색을 수행하는 경로에서 더 많은 문서를 가져오고, 나머지 하나는 프롬프트 캐시를 끈다. 이 중 어느 것이 지연 시간, 토큰, 비용, 오류, 라우팅 정확도를 움직였을까? 그리고 게이트는 움직인 변경을 잡아내면서도 평범한 날은 막지 않을 수 있을까?
이 질문은 두 부분으로 이루어져 있으며, 두 번째 부분이 더 어렵다. 릴리스가 측정한 메시지에서는 수치를 움직였더라도, 그 변화가 평범한 날에도 나타날 만한 범위 안에 있을 수 있다. 따라서 비교는 두 릴리스를 같은 메시지에서 실행해야 하고, 차이가 얼마나 움직일 수 있는지도 말해 주어야 한다. 이 장에서는 같은 메시지에서 두 릴리스를 비교하는 방법을 만들고, 이를 고정된 한계를 가진 게이트로 바꾼다. 각 트레이스에 릴리스를 표시해 쿼리가 둘을 나눌 수 있게 하고, 릴리스를 메시지별로 짝지으며, 모든 차이 옆에 구간을 붙인다.
스팬의 릴리스 마커
각 트레이스가 어느 릴리스에서 만들어졌는지 밝혀야 비교가 트레이스를 릴리스별로 나눌 수 있다. 2장에서 마커를 마련해 두었다. 리소스는 릴리스를 나타내는 service.version를 가지고, 각 추론 스팬은 함께 전송된 프롬프트를 나타내는 gen_ai.prompt.version를 가진다(스팬을 만드는 주체, 그리고 프롬프트 쌍이 나오는 요구 수준). 릴리스는 리소스의 service.version와 추론 스팬의 gen_ai.prompt.version로 표시되므로, 쿼리는 트레이스를 릴리스별로 나눌 수 있다.
마커는 단순한 라벨 이상의 역할을 한다. 마커가 없으면 일주일치 트레이스에 대한 쿼리는 여러 릴리스를 하나의 평균으로 섞어 버리고, 어느 릴리스도 자기 변화를 드러내지 못한다. 마커가 있으면 같은 쿼리가 릴리스마다 한 행씩 반환한다. 아래에서는 같은 메시지 60개를 기준선과 네 가지 변경 각각에서 다시 실행하고, 다섯 번의 재실행에서 나온 모든 스팬을 하나의 파일에 담는다. 각 재실행은 자기 마커를 유지하며, 스팬 ID는 하나의 순서에서 나오므로 두 재실행이 같은 ID를 공유하는 일은 없다.
1"""Replay the same 60 messages under each of the five releases, export every span to one store, and query the release2markers: the resource's service.version and the inference span's gen_ai.prompt.version. Each release's markers are the3only thing that tells its traces apart, so the query must give five distinct pairs. The span IDs come from one sequence,4so no two releases share an ID in the store."""5from lib.assistant import RELEASES6from lib.case import load_messages7from lib.export import write_jsonl8from lib.gate import release_spans9from lib.query import connect10from lib.report import fmt_int1112import tempfile13from pathlib import Path1415DAY = "2026-12-08"16FOLDERS = {"r0": "baseline-day-1", "r1": "release-prompt-v2", "r2": "release-model-swap",17 "r3": "release-top-8", "r4": "release-cache-off"}18PAIRED = {m.message_id for m in load_messages("2026-12-08-paired")} # the 60 messages, in every release's recording19rows = release_spans(DAY, FOLDERS, PAIRED)20with tempfile.TemporaryDirectory() as folder:21 rows_file = Path(folder) / "spans.jsonl" # the stored rows, as a file a query can read22 write_jsonl(rows_file, rows)23 db = connect(rows_file)24 markers = db.execute(25 "WITH inference AS (SELECT json_extract_string(resource, '$.\"service.version\"') AS version, "26 "json_extract_string(attributes, '$.\"gen_ai.prompt.version\"') AS prompt, "27 "json_extract_string(attributes, '$.\"gen_ai.prompt.name\"') AS name, trace_id FROM spans "28 "WHERE json_extract_string(attributes, '$.\"gen_ai.operation.name\"') = 'chat') "29 "SELECT version, prompt, name, count(*), count(DISTINCT trace_id) FROM inference "30 "GROUP BY version, prompt, name ORDER BY version, prompt, name").fetchall()31 per_version = db.execute(32 "SELECT json_extract_string(resource, '$.\"service.version\"') AS version, count(DISTINCT trace_id) "33 "FROM spans GROUP BY version ORDER BY version").fetchall()3435for version, prompt, name, calls, traces in markers:36 print(f"service.version {version}, gen_ai.prompt.version {prompt}, {name}: {fmt_int(calls)} inference spans")37for version, traces in per_version:38 print(f"service.version {version}, messages (traces): {fmt_int(traces)}")39pairs = {(version, prompt) for version, prompt, _, _, _ in markers}40assert pairs == {(r.service_version, r.prompt_version) for r in RELEASES.values() if r.name in FOLDERS}41assert all(traces == len(PAIRED) for _, traces in per_version) # every release answered every paired message
python release-markers-query.pyservice.version 1.0.0, gen_ai.prompt.version p1, ambrewick.answer: 33 inference spans
service.version 1.0.0, gen_ai.prompt.version p1, ambrewick.route: 60 inference spans
service.version 1.1.0, gen_ai.prompt.version p2, ambrewick.answer: 33 inference spans
service.version 1.1.0, gen_ai.prompt.version p2, ambrewick.route: 60 inference spans
service.version 1.2.0, gen_ai.prompt.version p1, ambrewick.answer: 16 inference spans
service.version 1.2.0, gen_ai.prompt.version p1, ambrewick.route: 60 inference spans
service.version 1.3.0, gen_ai.prompt.version p1, ambrewick.answer: 33 inference spans
service.version 1.3.0, gen_ai.prompt.version p1, ambrewick.route: 60 inference spans
service.version 1.4.0, gen_ai.prompt.version p1, ambrewick.answer: 33 inference spans
service.version 1.4.0, gen_ai.prompt.version p1, ambrewick.route: 60 inference spans
service.version 1.0.0, messages (traces): 60
service.version 1.1.0, messages (traces): 60
service.version 1.2.0, messages (traces): 60
service.version 1.3.0, messages (traces): 60
service.version 1.4.0, messages (traces): 60
2026.11.2판에서 duckdb 2.0.0에서 2.0.1(으)로에서 업데이트됨.
릴리스 이름이 있는 곳 찾기
+10 증명스팬의 릴리스 마커의 10장에서다시 읽는다
attribute에 기반한다. 출처는 1장 “직접 만드는 스팬” 절이다.
inference span에 기반한다. 출처는 2장 “Span types for each step” 절이다.
resource에 기반한다. 출처는 1장 “직접 만드는 스팬” 절이다.
이 연습이 다루던 내용이 새 판에서 바뀌었다. 2026.11.2판에서 바뀐 내용
25번째 줄은 스팬의 속성에서 릴리스 이름을 읽기 때문에 모든 릴리스가 None으로 출력되고 쌍 검사가 실패한다. 25번째 줄을 고쳐서, 이 절에서 릴리스 이름이 표시된다고 설명한 곳에서 릴리스 이름을 읽도록 하라.
작동 원리
쿼리는 추론 스팬을 두 마커로 묶어 세고, 각 릴리스가 만든 트레이스의 수도 센다. 모든 릴리스가 같은 메시지 60개에 응답하므로 트레이스 수는 서로 같다. 실행은 다섯 개의 마커 쌍이 릴리스 표에 나온 쌍과 정확히 일치하는지, 그리고 모든 릴리스가 모든 메시지에 응답했는지를 단언한다. 따라서 마커가 빠지면 행이 줄어드는 대신 실행이 실패한다.
각 릴리스는 메시지마다 하나씩, 60개의 트레이스를 만들었다. 표는 마커가 구분해 내는 내용을 보여 주며, 확인해야 할 수치는 응답 호출 수이다. 모델 교체가 이웃한 행과 다른 행이다.
| 릴리스 | 프롬프트 버전 | 응답 호출 |
|---|---|---|
| 기준선 | p1 | 33 inference spans |
| 프롬프트 변경 | p2 | 33 inference spans |
| 모델 교체 | p1 | 16 inference spans |
| Top-8 릴리스 | p1 | 33 inference spans |
| 캐시 해제 릴리스 | p1 | 33 inference spans |
모델 교체에서는 같은 메시지 60개에 대해 응답 호출이 기준선보다 적다. 응답 호출은 답장을 작성하는 모델 호출이며, 폴백으로 보내진 메시지는 응답 호출을 하지 않는다. 모델 교체에서 응답 호출이 적은 것은 더 많은 메시지를 폴백으로 보내기 때문이다. 바뀐 경로의 수는 이 장의 뒤에서 CI 게이트가 센다. 마커가 없으면 다섯 행은 하나로 합쳐지고, 표의 어떤 값도 어느 릴리스가 어느 호출을 했는지 알려 주지 못한다.
작업 규칙: 모든 트레이스에 릴리스와 프롬프트 버전을 표시하고, 수치를 읽기 전에 쿼리를 두 마커로 나누어라.
메시지 단위 쌍체 비교
서로 다른 메시지로 측정한 두 릴리스의 값이 다른 데에는 두 가지 이유가 있다. 릴리스 자체와 메시지다. 하루치 메시지는 편차가 매우 크다. 긴 요청도 있고, 대체 응답으로 라우팅되는 메시지도 있으며, 느린 도구를 기다리는 메시지도 있다. 두 릴리스를 같은 메시지에서 실행하면 각 메시지가 스스로의 대조군이 되므로 두 번째 이유가 각 차이에서 빠진다. 쌍체 비교는 두 릴리스를 같은 메시지에서 실행하고, 메시지마다 릴리스의 값에서 기준선의 값을 뺀 값을 요약한다.
이 방법은 Evaluating LLM Applications가 쌍체 비교라고 부르는 방법이다. 그 책은 판정을 빼지만, 이 책은 트레이스에서 읽은 값을 뺀다. 여기에 나오는 모든 지연 시간은 1장에서 설명한 대로 기록 머신인 2.10 GHz의 4-vCPU Intel Xeon에서 나온 값이며, 재생은 가상 시계에서 실행한다. 메시지 시간은 한 메시지의 모델 호출과 contacts 도구 호출에 기록된 소요 시간을 합한 값이며, 7장에서 센 수치가 바로 이것이다. 기록기가 호출 사이에 남긴 간격은 여기에 포함되지 않는다.
측정 항목마다 통계량이 따로 있다. 메시지 시간, 입력 토큰, 비용, 오류, 라우팅 정확도에서는 메시지별 차이의 평균이 통계량이다. 백분위수는 다르며, 본문은 각 차이가 어떤 통계량인지 밝힌다. 95번째 백분위수에서는 두 p95의 차이를 취하고 메시지를 함께 리샘플링한다. 리샘플링할 때마다 두 릴리스에 같은 메시지를 뽑고 양쪽에서 각각 95번째 백분위수를 구한다. 모든 차이의 구간은 7장의 백분위수 부트스트랩이며, 메시지를 대상으로 쌍으로 리샘플링해 구한다. 평균에서는 메시지별 차이의 평균이 통계량이고, p95에서는 두 p95의 차이가 통계량이다. 리샘플링 단위는 메시지이며 스팬이 아니다. 7장은 한 릴리스의 백분위수를 위해 그 부트스트랩을 만들었고, 여기서는 같은 리샘플링을 쌍에 적용한다.
여기서 입력 토큰은 기록된 개수이며, 각 개수가 어디서 나오는지는 6장에서 설명한다.
다음으로 예제는 각 변경을 그 변경이 기록된 메시지에서 기준선과 나란히 놓는다.
1"""Compare each release with baseline r0 on the same messages, in message time and input tokens: the mean of the per-message differences, and the p95 difference with the two p95s resampled jointly (PL-6). Each interval is a bootstrap of 2,000 resamples at 95 %, seed 20261207. The unpaired width for the input tokens is printed beside the paired one: the messages' own lengths cancel out of the paired difference."""2from lib.gate import measured, paired, paired_report34DAY, MODEL = "2026-12-08", "Qwen3-4B-Instruct-2507"5RELEASES_TO_COMPARE = [ # name, the release's recording folder, the model it ran6 ("r1", "release-prompt-v2", MODEL), # p2: six routing examples in the route prompt7 ("r2", "release-model-swap", "Qwen3-0.6B"),8 ("r3", "release-top-8", MODEL), # top 8 articles instead of 39 ("r4", "release-cache-off", MODEL), # a fresh state per call, so no cached prefix10]11base = measured("baseline-day-1", DAY, MODEL) # r0, the cache on, on all 200 messages of baseline day 112for name, folder, model in RELEASES_TO_COMPARE:13 _, before, after = paired(base, measured(folder, DAY, model)) # the messages this release recorded14 paired_report(name, before, after)
python paired-latency-and-tokens.pyr1, messages (paired with r0): 60
r1, r0 p95 message time on these messages: 17,128.2 ms
r1, message time, mean difference: 726.1 ms (95% interval 79.8 ms to 1,333.3 ms)
r1, message time, p95 difference: -345.3 ms (95% interval -495.9 ms to 2,301.0 ms)
r1, input tokens per message, mean difference: 90 (95% interval 70 to 115)
r1, input tokens, interval width paired: 45
r1, input tokens, interval width if unpaired: 276
r1, cost per 1,000 messages, mean difference: $0.006281 (95% interval $0.003197 to $0.009519)
r1, error rate, mean difference: +0.0% (95% interval +0.0% to +0.0%)
r1, route accuracy, mean difference: +3.3% (95% interval +0.0% to +8.3%)
r2, messages (paired with r0): 200
r2, r0 p95 message time on these messages: 18,351.2 ms
r2, message time, mean difference: -6,750.9 ms (95% interval -7,599.5 ms to -5,921.4 ms)
r2, message time, p95 difference: -14,109.1 ms (95% interval -16,749.8 ms to -12,105.6 ms)
r2, input tokens per message, mean difference: -200 (95% interval -258 to -148)
r2, input tokens, interval width paired: 110
r2, input tokens, interval width if unpaired: 137
r2, cost per 1,000 messages, mean difference: -$0.033156 (95% interval -$0.037326 to -$0.029012)
r2, error rate, mean difference: +0.0% (95% interval +0.0% to +0.0%)
r2, route accuracy, mean difference: -21.0% (95% interval -28.0% to -14.5%)
r3, messages (paired with r0): 60
r3, r0 p95 message time on these messages: 17,128.2 ms
r3, message time, mean difference: 2,222.5 ms (95% interval 1,099.6 ms to 3,462.8 ms)
r3, message time, p95 difference: 7,618.8 ms (95% interval 1,914.5 ms to 12,517.7 ms)
r3, input tokens per message, mean difference: 115 (95% interval 60 to 179)
r3, input tokens, interval width paired: 119
r3, input tokens, interval width if unpaired: 337
r3, cost per 1,000 messages, mean difference: $0.012542 (95% interval $0.006844 to $0.018909)
r3, error rate, mean difference: +0.0% (95% interval +0.0% to +0.0%)
r3, route accuracy, mean difference: +0.0% (95% interval +0.0% to +0.0%)
r4, messages (paired with r0): 60
r4, r0 p95 message time on these messages: 17,128.2 ms
r4, message time, mean difference: 2,881.5 ms (95% interval 2,209.1 ms to 3,677.3 ms)
r4, message time, p95 difference: 2,128.9 ms (95% interval 1,839.2 ms to 16,968.2 ms)
r4, input tokens per message, mean difference: 0 (95% interval 0 to 0)
r4, input tokens, interval width paired: 0
r4, input tokens, interval width if unpaired: 280
r4, cost per 1,000 messages, mean difference: $0.023233 (95% interval $0.018860 to $0.028303)
r4, error rate, mean difference: +0.0% (95% interval +0.0% to +0.0%)
r4, route accuracy, mean difference: +0.0% (95% interval +0.0% to +0.0%)
짝짓기가 프롬프트 변경의 토큰 구간을 좁히는 이유
+10 증명메시지 단위 쌍체 비교의 10장에서다시 읽는다
input tokens에 기반한다. 출처는 6장 “호출마다 세 가지 개수” 절이다.
interval에 기반한다. 출처는 7장 “Tail percentiles with intervals” 절이다.
prompt version에 기반한다. 출처는 10장 “스팬의 릴리스 마커” 절이다.
이 연습이 다루던 내용이 새 판에서 바뀌었다. 2026.11.2판에서 바뀐 내용
프롬프트 변경의 입력 토큰 구간은 짝을 지었을 때 폭이 45이고, 짝을 짓지 않으면 276이다. 짝짓기가 구간을 이만큼 좁히는 이유를 고르라.
작동 원리
쌍체로 비교하면 프롬프트 변경의 토큰 구간 너비가 쌍을 이루지 않을 때 276 토큰에서 45으로 좁아진다. 쌍을 이룬 60개 메시지에서 메시지당 입력 토큰은 90 (95% interval 70 to 115)만큼 늘며, 게이트가 포착해야 하는 변화가 바로 이 증가다.
평균 메시지 시간은 726.1 ms (95% interval 79.8 ms to 1,333.3 ms)만큼 늘고, 95번째 백분위수는 반대로 -345.3 ms (95% interval -495.9 ms to 2,301.0 ms)만큼 움직인다. 평균과 p95의 부호가 서로 다르고, p95의 구간은 0 아래에서 0을 훨씬 넘는 값까지 걸쳐 있다. 메시지 60개로는 꼬리가 어느 쪽으로 움직였는지 알 수 없다. p95는 여기에 출력만 하고 게이트에는 쓰지 않으며, 그 이유는 게이트가 놓치는 것에서 설명한다.
1,000개 메시지당 비용은 $0.006281 (95% interval $0.003197 to $0.009519)만큼 늘며, 6장에서 설명한 대로 이 책의 가격표 버전 book-2026-11-02으로 계산했다. 오류율은 변하지 않는다. 값은 +0.0% (95% interval +0.0% to +0.0%)이다. 라우팅 정확도의 차이는 +3.3% (95% interval +0.0% to +8.3%)이다. 구간이 0에서 시작하므로 이 릴리스가 라우팅을 바꾼다는 점은 입증되지 않았다.
모델 교체는 변화가 가장 큰 항목이며, 이 비교에는 그 항목의 모든 줄에 적용되는 단서가 붙는다. 0.6B의 프롬프트에는 더 작은 모델과 함께 /no_think도 들어 있으므로, 프롬프트 버전에서 설명하듯 이 교체는 순수한 모델 교체가 아니다. 프롬프트 버전은 여전히 p1로 표시된다. 평균 메시지 시간은 -6,750.9 ms (95% interval -7,599.5 ms to -5,921.4 ms)만큼 변한다. 라우팅 정확도는 -21.0% (95% interval -28.0% to -14.5%)만큼 변하며, 이 변화는 모델과 접미사가 함께 만든 것이다. 교체는 기준선 날의 메시지 200개 전체에서 실행되었다. 비용 줄은 가격표에서 0.6B의 행에 의존한다. 그 행은 이 책이 직접 썼으며 출처가 없다. 따라서 비용 차이 -$0.033156 (95% interval -$0.037326 to -$0.029012)은 가정한 단가만큼만 확실하다.
top-8 릴리스는 검색을 수행하는 세 경로에서 더 많은 문서를 가져온다. 7장은 추가된 컨텍스트에 따르는 프리필을 측정했다. 여기서 입력 토큰은 115 (95% interval 60 to 179)만큼, 평균 메시지 시간은 2,222.5 ms (95% interval 1,099.6 ms to 3,462.8 ms)만큼 늘어난다.
캐시 해제 릴리스는 입력 토큰이 변하지 않아야 하는 릴리스이며, 실제로도 변하지 않는다. 입력 총량의 차이는 0 (95% interval 0 to 0)이며, 모델이 읽는 프롬프트가 같기 때문이다. 비용은 $0.023233 (95% interval $0.018860 to $0.028303)만큼, 평균 메시지 시간은 2,881.5 ms (95% interval 2,209.1 ms to 3,677.3 ms)만큼 늘어난다. 출력된 줄에는 캐시된 개수가 아니라 입력 총량과 비용이 나오므로, 여기서는 비용 줄이 증거가 된다. 캐시된 개수를 어떻게 도출하는지는 6장에서 설명한다.
그림 10.1는 릴리스마다 두 가지 차이를 구간과 함께 그린다. 왼쪽은 p95 메시지 시간이고 오른쪽은 메시지당 입력 토큰이다. 0선이 기준이다. 프롬프트 변경의 p95 구간은 0선을 가로지르며, 이것이 꼬리의 불확실성을 한 장의 그림으로 보여 준다. 프롬프트 변경, 모델 교체, top-8 릴리스의 토큰 구간은 0에서 멀리 떨어져 있고, 캐시 해제 릴리스의 토큰 구간은 입력 총량이 말해 주듯 0 위에 놓인다.
1"""Draw each release's paired difference from baseline r0 on the same messages, in p95 message time and in input tokens per message, each with its interval. A line that crosses the zero line is a difference the interval cannot rule out; the p95 uses messages resampled jointly, and the token mean uses per-message differences."""2from lib.gate import P95, measured, paired3from lib.figures import ACCENT, INK, MUTED, new_figure, save4from lib.report import fmt_int, fmt_ms5from lib.stats import paired_interval, paired_mean_difference6from matplotlib.ticker import FuncFormatter78DAY, MODEL = "2026-12-08", "Qwen3-4B-Instruct-2507"9RELEASES_TO_DRAW = [ # name, the row's label as the prose gives it, the recording folder, the model; each against r010 ("r1", "Prompt change", "release-prompt-v2", MODEL),11 ("r2", "Model swap", "release-model-swap", "Qwen3-0.6B"),12 ("r3", "Top-8 release", "release-top-8", MODEL),13 ("r4", "Cache-off release", "release-cache-off", MODEL),14]15def show(line, point, low, high, fmt):16 """Print one difference with its 95% interval."""17 print(line, fmt(round(point)), f"(interval {fmt(round(low))} to {fmt(round(high))})")1819base = measured("baseline-day-1", DAY, MODEL)20fig, (left, right) = new_figure(height=3.2, columns=2, sharex=False)21ticks = []22for row, (name, label, folder, model) in zip(range(len(RELEASES_TO_DRAW))[::-1], RELEASES_TO_DRAW): # the top row first23 ids, before, after = paired(base, measured(folder, DAY, model))24 time_p, (time_low, time_high) = paired_interval([m["time"] for m in before], [m["time"] for m in after], P95)25 token_p, (token_low, token_high) = paired_interval([m["tokens"] for m in before], [m["tokens"] for m in after],26 paired_mean_difference)27 show(f"{name}, p95 message time, difference:", time_p, time_low, time_high, fmt_ms)28 show(f"{name}, input tokens per message, difference:", token_p, token_low, token_high, fmt_int)29 left.hlines(row, time_low / 1e6, time_high / 1e6, color=MUTED, linewidth=3)30 left.scatter([time_p / 1e6], [row], color=ACCENT, zorder=3)31 right.hlines(row, token_low, token_high, color=MUTED, linewidth=3)32 right.scatter([token_p], [row], color=ACCENT, zorder=3)33 ticks.append((row, f"{label} (n = {len(ids)})"))34for axis in (left, right):35 axis.axvline(0, color=INK, linewidth=0.8) # no difference: a release that changed nothing36 axis.set_yticks(*zip(*ticks))37right.tick_params(axis="y", labelleft=False) # the rows are named once, on the left38left.set_xlabel("difference in p95\nmessage time (ms)")39left.set_xticks([-10_000, 0, 10_000])40left.xaxis.set_major_formatter(FuncFormatter(lambda ms, _: f"{ms:,.0f}".replace("-", "−"))) # thousands separators41right.set_xlabel("mean difference in input\ntokens per message")42right.set_xticks([-200, 0, 200])43save(fig, "paired-differences")
python figure-paired-differences.pyr1, p95 message time, difference: -345.3 ms (interval -495.9 ms to 2,301.0 ms)
r1, input tokens per message, difference: 90 (interval 70 to 115)
r2, p95 message time, difference: -14,109.1 ms (interval -16,749.8 ms to -12,105.6 ms)
r2, input tokens per message, difference: -200 (interval -258 to -148)
r3, p95 message time, difference: 7,618.8 ms (interval 1,914.5 ms to 12,517.7 ms)
r3, input tokens per message, difference: 115 (interval 60 to 179)
r4, p95 message time, difference: 2,128.9 ms (interval 1,839.2 ms to 16,968.2 ms)
r4, input tokens per message, difference: 0 (interval 0 to 0)
figure: figures/paired-differences.svg
작업 규칙: 요약하기 전에 메시지마다 기준선의 값을 뺀다. 백분위수에서는 메시지를 함께 리샘플링하고, 각 차이를 개수와 구간과 함께 출력한다.
이 부분은 아직 번역되지 않았으므로 영어로 표시된다.
Prompt versions
The releases differ in their prompts, and one of them differs in its model as well, so this section says what changed in each prompt before the gate judges the numbers. The baseline's prompt is p1. The prompt change is p2, which adds six routing examples to the route prompt. The six examples add 86 tokens to every route call, and every message makes one. The rest of the prompt change's rise, 4 tokens per message, and the width of its paired interval come from the 2 messages whose route changed, as the paired comparison shows. The markers confirm that both prompts make one route call per message, on the same 60 messages. The top-8 release keeps p1's template, and only its retrieved context grows.
The model swap keeps p1 as its prompt version, and this is the point to read carefully. Its prompt is not the baseline's, because it carries /no_think. Qwen3-0.6B is hybrid-thinking, and its model card at the pinned commit says that with thinking enabled the model always writes a <think>...</think> block, whose content may be empty when thinking is turned off. The recording script adds the suffix to the prompts. We decided that the release carries it, and that its prompt version stays p1. The release marker cannot show the suffix, so a query that splits by prompt version would count the model swap as the baseline's prompt. Under the suffix, the recording's model replies open with an empty block in 256 of their 257, and the assistant's parser drops that block from each reply. The pair still costs output tokens: on average, each route call's output grows by 4 tokens. One answer reply writes its reasoning into its block instead, and the parser drops that as well.
That matters for the token comparison. The two models share one Qwen3 tokenizer. The book checked that on three texts, and the 4B and the 0.6B give identical token IDs for each, so their input counts compare directly. The check covers three texts, not every message, and the chapter claims no more than that. The model swap's token difference is therefore the smaller model and the suffix together. The model-swap gate prints the split: the suffix adds 4 tokens to each route call, and the answer calls change it by -204 tokens per message, since the messages routed to fallback make no such call.
Working rule: Read a release's prompt version with the prompt's differences beside it. Say beside any model comparison whether the prompt changed as well.
CI 게이트
비교는 숫자를 내놓고, 게이트는 그 숫자를 결정으로 바꾼다. 회귀 게이트는 CI에서 실행하는 검사로, 트레이스에서 읽은 숫자가 한계를 넘어 움직였을 때 릴리스의 병합을 막는다. 이때 판단은 쌍체 구간을 기준으로 한다. 회귀란 릴리스의 변경 때문에 트레이스에서 얻은 숫자가 한계가 허용하는 수준보다 나빠지는 것이다. 판단은 구간에서 한계에 가장 가까운 끝으로 한다. 한계는 아래에서 정한다. 구간은 7장에서 하루치 메시지로 측정한 숫자에 대해 만든 구간이다. Evaluating LLM Applications는 변경의 병합을 막는 이 규칙을 공유하고, Business Intelligence with Agents' 회귀 게이트는 다른 규칙을 쓴다. Evaluating LLM Applications는 점추정치만으로 실패 처리하는 단순 게이트도 설명한다. 여기서 다루는 게이트는 구간을 기다린다.
이 게이트의 역할은 하나다. 두 경우에 같은 규칙을 적용하면서, 기준선의 2일째는 잡지 않고 프롬프트 변경은 잡아내는 것이다. 다섯 가지 규칙은 코드에 고정되어 있고, 게이트는 판단하는 모든 줄을 출력한다. 메시지 시간, 입력 토큰, 비용은 같은 메시지에서 기준선 평균의 10분의 1까지 오를 수 있다. 그래서 메시지가 60개일 때와 200개일 때 한계가 다르다. 오류율은 2포인트까지 오를 수 있고, 경로 정확도는 5포인트까지 떨어질 수 있다. 각 규칙은 릴리스 차이의 구간을 읽고, 그 구간에서 한계에 가장 가까운 끝이 한계를 넘으면 릴리스를 플래그한다. 상승을 보는 규칙에서는 아래쪽 끝이 그 끝이다. 경로 정확도의 하락을 보는 규칙에서는 위쪽 끝이다. 따라서 플래그는 릴리스가 95% 구간 밖에서 한계보다 나쁘다는 뜻이다. 구간이 한계를 넘어 걸쳐 있기만 한 릴리스는 플래그되지 않는다.
이 한계는 우리가 정했으며, 이 장은 이 기록에 맞추어 조정하지 않고 출력된 그대로 적용한다. 상대 한계는 기준선의 평균에 비례한다. 오류율의 기준선은 0이므로 상대 한계로는 여유가 없고, 그 한계는 2포인트다. 경로 정확도는 메시지 중 일부의 비율이므로 포인트 단위로 움직이고, 한계는 5포인트다. 규칙은 트레이스만 읽으며 답변의 본문은 읽지 않는다. 경로 정확도에서는 게이트가 응답이 지목한 경로를 읽어 시나리오 표와 대조한다.
오류 규칙은 8장이 주는 정의를 쓴다. 이 정의에서는 토큰 상한에서 잘린 응답이나 경로를 지목하지 않은 경로 응답은 오류가 아니다. 8장은 이런 경우를 품질 발견 사항으로 세며, 경로 정확도는 이미 둘째 경우를 센다.
게이트는 평범한 하루를 통과시켜야 한다. 그렇지 않으면 팀이 게이트를 읽지 않게 된다. 기준선 2일째를 1일째와 비교해 같은 규칙과 한계로 게이트를 돌리면 통과하는지 확인할 수 있다.
1"""Gate baseline day 2 against baseline day 1, both on release r0, with the same rules and limits as the prompt release's gate. The two days share no message, so each interval resamples each day on its own. The day is a normal day with no incident, and the gate must pass it, or a gate that flags every normal day would never reach CI."""2from lib.gate import judge, measured3from lib.report import fmt_int45DAY, MODEL = "2026-12-08", "Qwen3-4B-Instruct-2507"6before = measured("baseline-day-1", DAY, MODEL) # r0 on all 200 messages of baseline day 17after = measured("baseline-day-2", "2026-12-10", MODEL) # r0 again, on 80 other messages, two days later8print("messages, baseline day 1:", fmt_int(len(before)))9print("messages, baseline day 2:", fmt_int(len(after)))10print("messages shared by the two days:", fmt_int(len(set(before) & set(after)))) # no message is in both11verdict, flagged = judge("baseline day 2 against day 1", list(before.values()), list(after.values()), paired=False)12assert verdict == "pass" and flagged == [] # the same release on a normal day must pass the same gate
python gate-on-baseline-day-two.pymessages, baseline day 1: 200
messages, baseline day 2: 80
messages shared by the two days: 0
baseline day 2 against day 1, message time, mean: 168.8 ms, limit 801.9 ms (95% interval -1,599.0 ms to 1,895.0 ms)
baseline day 2 against day 1, message time, mean, flagged: no
baseline day 2 against day 1, input tokens per message, mean: -5, limit 52 (95% interval -108 to 99)
baseline day 2 against day 1, input tokens per message, mean, flagged: no
baseline day 2 against day 1, cost per message, mean, per 1,000 messages: $0.000545, limit $0.003781 (95% interval -$0.007950 to $0.008940)
baseline day 2 against day 1, cost per message, mean, flagged: no
baseline day 2 against day 1, error rate: +0.0%, limit +2.0% (95% interval +0.0% to +0.0%)
baseline day 2 against day 1, error rate, flagged: no
baseline day 2 against day 1, route accuracy: -3.3%, limit -5.0% (95% interval -14.5% to +7.8%)
baseline day 2 against day 1, route accuracy, flagged: no
baseline day 2 against day 1, gate verdict: pass
메시지가 겹칠 때만 릴리스를 짝지어 비교한다
+10 증명interval에 기반한다. 출처는 7장 “Tail percentiles with intervals” 절이다.
prompt version에 기반한다. 출처는 10장 “스팬의 릴리스 마커” 절이다.
이 연습이 다루던 내용이 새 판에서 바뀌었다. 2026.11.2판에서 바뀐 내용
11행은 두 기준선 날짜를 짝지은 것으로 판정한다. 두 날짜 모두 같은 모델의 릴리스 r0이기 때문이다. 그러나 두 날짜는 공통된 메시지가 없으므로, 게이트가 메시지가 허용하는 방식으로 두 날짜를 판정하도록 11행을 바꿔라.
작동 원리
메시지 시간이 플래그되지 않는 이유
+10 증명interval에 기반한다. 출처는 7장 “Tail percentiles with intervals” 절이다.
이 연습이 다루던 내용이 새 판에서 바뀌었다. 2026.11.2판에서 바뀐 내용
게이트는 기준선 2일차의 메시지 시간을 플래그하지 않는다. 그 구간이 한쪽 끝에서는 한계를 넘어가는데도 그렇다. 이 절의 이유 중 어느 것이 규칙에 대한 이 판정을 설명하는가?
작동 원리
두 날이 공유하는 메시지는 0개이므로 구간은 쌍체가 아니다. 메시지 시간은 168.8 ms, limit 801.9 ms (95% interval -1,599.0 ms to 1,895.0 ms)만큼 오르는데, 그 구간의 아래쪽 끝은 한계보다 훨씬 아래에 있으므로 규칙은 플래그하지 않는다. 다른 규칙도 통과하며 판정은 pass이다.
쌍체로 보면 프롬프트 변경은 토큰에서 실패해야 하고, 쌍체가 아니면 같은 60개 메시지가 통과해야 한다. 두 판단은 같은 메시지에서 실행되며, 실행은 두 결과를 모두 단언한다.
1"""Gate the prompt-change release r1 against r0 on the same 60 messages, with the gate's own rules. The gate reads the traces only: message time, input tokens, cost, errors and route accuracy. A rule flags a release when the end of its interval nearest the limit lies past the limit. The prompt change adds tokens to every route call, and the gate catches it only because the messages are paired: the same 60 messages judged as unrelated samples pass."""2from lib.gate import judge, measured, paired, tokens_by_step3from lib.report import fmt_int4from lib.stats import mean_of, paired_interval, paired_mean_difference56DAY, MODEL = "2026-12-08", "Qwen3-4B-Instruct-2507"7before = measured("baseline-day-1", DAY, MODEL)8after = measured("release-prompt-v2", DAY, MODEL)9ids, base, release = paired(before, after) # the paired 60: r0 has every one of them10print("messages (paired):", fmt_int(len(ids)))11verdict, flagged = judge("r1 against r0", base, release, paired=True)12assert verdict == "fail" and flagged == ["input tokens per message, mean"] # the prompt change, and only its tokens13assert "message time, mean" not in flagged # its message time is not flagged: the interval's end stays under the limit14# The same 60 messages, judged as if they were two unrelated samples: the same release passes.15unpaired, unpaired_flagged = judge("r1 against r0, unpaired", base, release, paired=False)16assert unpaired == "pass" and unpaired_flagged == [] # without the pairing, the gate misses the change it must catch17steps0, steps1 = tokens_by_step("baseline-day-1", DAY, MODEL), tokens_by_step("release-prompt-v2", DAY, MODEL)18def change(steps, step):19 """r1 minus r0 in input tokens, for each message, in one step's calls; zero where the message made no such call."""20 return {i: steps[i].get(step, {"input": 0})["input"] - steps0[i].get(step, {"input": 0})["input"] for i in ids}21route_in, answer_in = change(steps1, "route"), change(steps1, "answer")22changed = {i for i in ids if before[i]["route"] != after[i]["route"]}23assert len(set(route_in.values())) == 1 # the six examples add the same tokens to every route call24assert all(answer_in[i] == 0 for i in ids if i not in changed) # only a message whose route changed gets another answer call25route_share, answer_share = mean_of(list(route_in.values())), mean_of(list(answer_in.values()))26assert route_share + answer_share == mean_of([m["tokens"] for m in release]) - mean_of([m["tokens"] for m in base])27print("r1 against r0, route call input tokens per call, mean difference:", fmt_int(round(route_share)))28print("r1 against r0, messages whose route changed:", fmt_int(len(changed)))29print("r1 against r0, input tokens per message, answer calls' share:", fmt_int(round(answer_share)))30tokens_base, tokens_release = [m["tokens"] for m in base], [m["tokens"] for m in release]31_, (token_low, _) = paired_interval(tokens_base, tokens_release, paired_mean_difference)32print("r1 against r0, input tokens per message, low end of interval:", fmt_int(round(token_low)))33print("r1 against r0, input tokens per message, limit:", fmt_int(round(mean_of(tokens_base) / 10)))
python gate-on-prompt-release.pymessages (paired): 60
r1 against r0, message time, mean: 726.1 ms, limit 737.3 ms (95% interval 79.8 ms to 1,333.3 ms)
r1 against r0, message time, mean, flagged: no
r1 against r0, input tokens per message, mean: 90, limit 49 (95% interval 70 to 115)
r1 against r0, input tokens per message, mean, flagged: yes
r1 against r0, cost per message, mean, per 1,000 messages: $0.006281, limit $0.003453 (95% interval $0.003197 to $0.009519)
r1 against r0, cost per message, mean, flagged: no
r1 against r0, error rate: +0.0%, limit +2.0% (95% interval +0.0% to +0.0%)
r1 against r0, error rate, flagged: no
r1 against r0, route accuracy: +3.3%, limit -5.0% (95% interval +0.0% to +8.3%)
r1 against r0, route accuracy, flagged: no
r1 against r0, gate verdict: fail
r1 against r0, unpaired, message time, mean: 726.1 ms, limit 737.3 ms (95% interval -1,627.6 ms to 3,141.5 ms)
r1 against r0, unpaired, message time, mean, flagged: no
r1 against r0, unpaired, input tokens per message, mean: 90, limit 49 (95% interval -45 to 231)
r1 against r0, unpaired, input tokens per message, mean, flagged: no
r1 against r0, unpaired, cost per message, mean, per 1,000 messages: $0.006281, limit $0.003453 (95% interval -$0.005244 to $0.018074)
r1 against r0, unpaired, cost per message, mean, flagged: no
r1 against r0, unpaired, error rate: +0.0%, limit +2.0% (95% interval +0.0% to +0.0%)
r1 against r0, unpaired, error rate, flagged: no
r1 against r0, unpaired, route accuracy: +3.3%, limit -5.0% (95% interval -10.0% to +16.7%)
r1 against r0, unpaired, route accuracy, flagged: no
r1 against r0, unpaired, gate verdict: pass
r1 against r0, route call input tokens per call, mean difference: 86
r1 against r0, messages whose route changed: 2
r1 against r0, input tokens per message, answer calls' share: 4
r1 against r0, input tokens per message, low end of interval: 70
r1 against r0, input tokens per message, limit: 49
토큰 상승은 구간의 아래쪽 끝에서도 한계를 넘는다. 토큰 70에 대해 한계는 49이다. 규칙은 플래그하고, 릴리스의 판정은 fail이다. 플래그는 입력 토큰에만 해당한다.
메시지 시간은 726.1 ms, limit 737.3 ms (95% interval 79.8 ms to 1,333.3 ms)만큼 올라 한계 아래이고, 구간에서 더 가까운 끝도 한계 아래다. 위쪽 끝은 한계를 넘지만 규칙은 한계에 더 가까운 끝을 읽으므로 플래그하지 않는다. 비용은 메시지 1,000개당 $0.006281, limit $0.003453 (95% interval $0.003197 to $0.009519)만큼 오른다. 아래쪽 끝이 한계 아래이므로 비용도 플래그되지 않는다. 같은 메시지에서 토큰은 오르는데도 그렇다.
서로 무관한 표본으로 판단하면 같은 60개 메시지가 통과한다. 토큰 상승은 여전히 90, limit 49 (95% interval -45 to 231)이지만, 구간이 0 아래에서 한계 위까지 걸쳐 있고 더 가까운 끝이 한계 아래이므로 판정은 pass이다. 그 이유는 쌍체 비교의 구간 너비에 있다. 공유하는 메시지는 구간을 변경을 꿰뚫어 볼 만큼 좁게 유지하고, 쌍체가 아닌 구간은 너무 넓어 변경을 보지 못한다. 게이트가 변경을 잡는 것은 메시지가 쌍을 이루기 때문이다.
작업 규칙: 메시지가 겹치는 릴리스는 쌍으로 묶고, 각 규칙은 구간에서 한계에 가장 가까운 끝으로 판단한다. 플래그를 눈으로 확인할 수 있도록 모든 줄을 출력한다.
다른 변경 게이트하기
모델 교체를 200개 메시지 전체에 게이트하면 다른 양상의 실패가 나타난다. 이 변경에서는 양이 줄어드는데, 규칙은 이를 통과시킨다. 경로 정확도도 떨어지는데, 이는 규칙 하나가 잡아낸다.
1"""Gate release r2, the 0.6B model swap, against r0 on the same 200 messages, with the same rules and limits. Its route accuracy falls, and the gate flags it. Its message time, input tokens and cost fall too, and the rules for those amounts pass a fall. The fall comes from the answer calls: r2 routes more messages to the fallback reply, which makes no answer call. The suffix adds a few tokens to every route call. The gate reads each message's route reply against the route its scenario gives, never an answer."""2from lib.gate import judge, measured, paired, tokens_by_step, to_decimal3from lib.report import fmt_int, fmt_ms, fmt_usd4from lib.stats import mean_of56DAY, MODEL, SWAP = "2026-12-08", "Qwen3-4B-Instruct-2507", "Qwen3-0.6B"7before = measured("baseline-day-1", DAY, MODEL)8after = measured("release-model-swap", DAY, SWAP) # r2: the 0.6B model, on all 200 messages9ids, base, release = paired(before, after)10verdict, flagged = judge("r2 against r0", base, release, paired=True)11print("messages (paired):", fmt_int(len(ids)))12assert verdict == "fail" and flagged == ["route accuracy"] # the model swap is caught on route accuracy alone1314steps0, steps2 = tokens_by_step("baseline-day-1", DAY, MODEL), tokens_by_step("release-model-swap", DAY, SWAP)15def change(step, field):16 """r2 minus r0 for each message, in one step's calls; zero where the message made no such call."""17 return [steps2[i].get(step, {field: 0})[field] - steps0[i].get(step, {field: 0})[field] for i in ids]18answered0 = {i for i in ids if "answer" in steps0[i]}19answered2 = {i for i in ids if "answer" in steps2[i]}20print("messages answered by r0 and not by r2:", fmt_int(len(answered0 - answered2)))21print("messages answered by r2 and not by r0:", fmt_int(len(answered2 - answered0)))22route_in, answer_in = change("route", "input"), change("answer", "input")23assert len(set(route_in)) == 1 # every route call grew by the same amount: the suffix's tokens24route_share, answer_share = mean_of(route_in), mean_of(answer_in)25assert route_share + answer_share == mean_of([m["tokens"] for m in release]) - mean_of([m["tokens"] for m in base])26print("r2 against r0, route call input tokens per call, mean difference:", fmt_int(round(route_share)))27print("r2 against r0, route call output tokens per call, mean difference:",28 fmt_int(round(mean_of(change("route", "output")))))29print("r2 against r0, input tokens per message, route calls' share:", fmt_int(round(route_share)))30print("r2 against r0, input tokens per message, answer calls' share:", fmt_int(round(answer_share)))31print("r2 against r0, message time, answer calls' share:", fmt_ms(round(mean_of(change("answer", "time")))))32print("r2 against r0, cost per 1,000 messages, answer calls' share:",33 fmt_usd(to_decimal(mean_of(change("answer", "cost")) * 1000)))34replies = [text for i in ids for step in steps2[i].values() for text in step["replies"]]35empty = [text for text in replies if text.startswith("<think>\n\n</think>")]36assert all(text.startswith("<think>") for text in replies) # the 0.6B still writes its block under /no_think37print("r2, model replies:", fmt_int(len(replies)))38print("r2, model replies with an empty <think> block:", fmt_int(len(empty)))39print("r2, model replies with text in their <think> block:", fmt_int(len(replies) - len(empty)))
python gate-on-model-swap.pyr2 against r0, message time, mean: -6,750.9 ms, limit 801.9 ms (95% interval -7,599.5 ms to -5,921.4 ms)
r2 against r0, message time, mean, flagged: no
r2 against r0, input tokens per message, mean: -200, limit 52 (95% interval -258 to -148)
r2 against r0, input tokens per message, mean, flagged: no
r2 against r0, cost per message, mean, per 1,000 messages: -$0.033156, limit $0.003781 (95% interval -$0.037326 to -$0.029012)
r2 against r0, cost per message, mean, flagged: no
r2 against r0, error rate: +0.0%, limit +2.0% (95% interval +0.0% to +0.0%)
r2 against r0, error rate, flagged: no
r2 against r0, route accuracy: -21.0%, limit -5.0% (95% interval -28.0% to -14.5%)
r2 against r0, route accuracy, flagged: yes
r2 against r0, gate verdict: fail
messages (paired): 200
messages answered by r0 and not by r2: 59
messages answered by r2 and not by r0: 4
r2 against r0, route call input tokens per call, mean difference: 4
r2 against r0, route call output tokens per call, mean difference: 4
r2 against r0, input tokens per message, route calls' share: 4
r2 against r0, input tokens per message, answer calls' share: -204
r2 against r0, message time, answer calls' share: -5,706.8 ms
r2 against r0, cost per 1,000 messages, answer calls' share: -$0.027870
r2, model replies: 257
r2, model replies with an empty <think> block: 256
r2, model replies with text in their <think> block: 1
각 단계의 변화에 모든 메시지를 포함한다
+10 증명다른 변경 게이트하기의 10장에서다시 읽는다
input tokens에 기반한다. 출처는 6장 “호출마다 세 가지 개수” 절이다.
prompt version에 기반한다. 출처는 10장 “스팬의 릴리스 마커” 절이다.
token count에 기반한다. 출처는 6장 “호출마다 세 가지 개수” 절이다.
이 연습이 다루던 내용이 새 판에서 바뀌었다. 2026.11.2판에서 바뀐 내용
17행은 두 실행에서 같은 호출을 한 메시지만 남기므로, 단계 평균이 일부 메시지를 제외한다. 짝지은 집합의 모든 메시지가 각 단계의 변화에 반영되도록 고친다.
작동 원리
양이 줄어드는 까닭은 모델 교체로 59개의 메시지에서 기준선이 수행했던 답변 호출이 사라지기 때문이다. 이 답변 호출은 메시지당 입력 토큰 수를 -204만큼 바꾼다. 접미사는 경로 호출마다 토큰을 4만큼 더하고, 이 둘이 합쳐져 감소가 나타난다. 이 양에 대한 규칙은 증가를 표시하므로 감소는 규칙을 통과한다. 게이트가 이 양에서 통과하는 것은 경로 실패의 결과이지 더 저렴한 모델 때문이 아니다.
경로 정확도는 -21.0%, limit -5.0% (95% interval -28.0% to -14.5%)만큼 변하고, 그 구간의 상한이 한계를 넘으므로 해당 규칙이 이를 표시하며 이 릴리스의 판정은 fail이다. 더 작은 모델을 고르는 문제는 Small Open Models에서 다루며, 이 장에서는 다루지 않는다. 이 릴리스는 프롬프트 버전에서 설명한 대로 /no_think를 쓴 0.6B 모델이므로, 경로 변화는 모델과 접미사 양쪽에 속한다. 오류율은 움직이지 않는다. +0.0%, limit +2.0% (95% interval +0.0% to +0.0%)이며, 이는 이 장의 다른 릴리스와 일치한다.
경로 검사는 경로가 시나리오 표와 다르면 틀린 것으로 센다. 이어지는 답변은 읽지 않는다. 경로는 맞지만 답변이 틀린 경우는 이 규칙을 통과한다.
top-8 릴리스와 캐시 끄기 릴리스에도 같은 짝지은 60개 메시지에 같은 게이트를 적용하며, 예제는 두 릴리스를 모두 실행한다.
1"""Gate the top-8 release r3 and the cache-off release r4 against r0, each on the same 60 paired messages, with the same rules and limits as the other gates. The top-8 release retrieves more articles, so its input tokens rise, and its time and cost rise with them. The cache-off release sends the same prompts, so its input total does not move, but its cost and time rise. The gate flags r3 on all three amounts and r4 on time and cost alone."""2from lib.gate import judge, measured, paired3from lib.report import fmt_int45DAY, MODEL = "2026-12-08", "Qwen3-4B-Instruct-2507"6before = measured("baseline-day-1", DAY, MODEL)7verdicts = {}8for name, folder in (("r3", "release-top-8"), ("r4", "release-cache-off")):9 ids, base, release = paired(before, measured(folder, DAY, MODEL))10 print(f"{name} against r0, messages (paired):", fmt_int(len(ids)))11 verdicts[name] = judge(f"{name} against r0", base, release, paired=True)12assert verdicts["r3"] == ("fail", ["message time, mean", "input tokens per message, mean", "cost per message, mean"])13assert verdicts["r4"] == ("fail", ["message time, mean", "cost per message, mean"]) # its input total does not move
python gate-on-retrieval-and-cache.pyr3 against r0, messages (paired): 60
r3 against r0, message time, mean: 2,222.5 ms, limit 737.3 ms (95% interval 1,099.6 ms to 3,462.8 ms)
r3 against r0, message time, mean, flagged: yes
r3 against r0, input tokens per message, mean: 115, limit 49 (95% interval 60 to 179)
r3 against r0, input tokens per message, mean, flagged: yes
r3 against r0, cost per message, mean, per 1,000 messages: $0.012542, limit $0.003453 (95% interval $0.006844 to $0.018909)
r3 against r0, cost per message, mean, flagged: yes
r3 against r0, error rate: +0.0%, limit +2.0% (95% interval +0.0% to +0.0%)
r3 against r0, error rate, flagged: no
r3 against r0, route accuracy: +0.0%, limit -5.0% (95% interval +0.0% to +0.0%)
r3 against r0, route accuracy, flagged: no
r3 against r0, gate verdict: fail
r4 against r0, messages (paired): 60
r4 against r0, message time, mean: 2,881.5 ms, limit 737.3 ms (95% interval 2,209.1 ms to 3,677.3 ms)
r4 against r0, message time, mean, flagged: yes
r4 against r0, input tokens per message, mean: 0, limit 49 (95% interval 0 to 0)
r4 against r0, input tokens per message, mean, flagged: no
r4 against r0, cost per message, mean, per 1,000 messages: $0.023233, limit $0.003453 (95% interval $0.018860 to $0.028303)
r4 against r0, cost per message, mean, flagged: yes
r4 against r0, error rate: +0.0%, limit +2.0% (95% interval +0.0% to +0.0%)
r4 against r0, error rate, flagged: no
r4 against r0, route accuracy: +0.0%, limit -5.0% (95% interval +0.0% to +0.0%)
r4 against r0, route accuracy, flagged: no
r4 against r0, gate verdict: fail
두 릴리스 모두 실패한다. top-8 릴리스는 세 양 모두에서 걸리며, 입력 토큰은 메시지당 115, limit 49 (95% interval 60 to 179)만큼 증가한다. 캐시 끄기 릴리스는 입력이 그대로이므로 시간과 비용에서만 걸리고, 비용은 메시지 1,000개당 $0.023233, limit $0.003453 (95% interval $0.018860 to $0.028303)만큼 증가한다.
| 비교 | 메시지 | 판정 | 표시된 규칙 |
|---|---|---|---|
| 기준선 2일차 대 1일차, 짝짓지 않음 | 80 | pass | 없음 |
| 프롬프트 변경 대 기준선, 짝지음 | 60 | fail | 입력 토큰 |
| 프롬프트 변경 대 기준선, 짝짓지 않음 | 60 | pass | 없음 |
| 모델 교체 대 기준선, 짝지음 | 200 | fail | 경로 정확도 |
| top-8 릴리스 대 기준선, 짝지음 | 60 | fail | 메시지 시간, 입력 토큰, 비용 |
| 캐시 끄기 릴리스 대 기준선, 짝지음 | 60 | fail | 메시지 시간, 비용 |
네 변경은 각각 게이트가 읽는 무언가를 움직였고, 게이트는 각각을 표시한다. 프롬프트 변경은 토큰으로, 모델 교체는 경로로, top-8 릴리스는 세 양 모두에서, 캐시 끄기 릴리스는 시간과 비용에서 표시된다. 평범한 날은 통과하고, 오류율을 움직인 릴리스는 없다. 이로써 게이트에 준 규칙의 범위에서 장 첫머리의 질문에 답했다.
작업 규칙: 표시된 규칙마다 그 규칙이 읽는 양을 확인하고, 릴리스의 무엇이 그 양을 움직였는지 묻는다.
게이트가 놓치는 것
게이트는 읽지 않는 것은 그대로 통과시킨다. 다섯 가지 규칙은 메시지 시간, 입력 토큰, 비용, 오류율, 경로 정확도를 읽는데, 릴리스는 게이트가 전혀 보지 못하는 다른 것을 바꿀 수 있다. 그중 네 가지가 이 장에서 중요하다.
첫째는 품질이다. 게이트는 답변이 아니라 트레이스를 읽는다. 릴리스가 모든 메시지를 올바르게 라우팅하고 토큰 수와 시간을 유지하면서도 더 나쁜 답변을 쓸 수 있으며, 이 게이트는 그런 릴리스를 통과시킨다. 답변을 판정하는 일은 별개의 작업이다. LLM 애플리케이션 평가는 이를 위해 코드 검사를 제시하는데, 이 검사는 답변의 텍스트를 항목 자체의 기준 답변과 대조하여 읽는다. 품질의 퇴행에는 이런 종류의 검사가 필요하며, 같은 메시지에 같은 쌍체 비교로 실행해야 한다. 이 장은 그러한 검사를 실행하지 않는다. 이 책은 어떤 답변의 품질도 판정하지 않는다.
둘째는 꼬리이다. 95번째 백분위수는 출력되지만 게이트의 대상은 아니다. 쌍을 이룬 60개 메시지에서 프롬프트 변경의 p95 차이는 아래를 향하고 평균은 위를 향하며, 쌍체 비교가 보여 주듯 p95의 구간은 평균의 구간보다 훨씬 넓다. 게이트가 평균을 읽는 이유는 메시지가 60개일 때 두 값 중 평균의 구간이 더 좁기 때문이다. 꼬리가 길어진 릴리스도 평균만 보는 이 게이트는 통과할 수 있다.
셋째는 구간 자체이다. 규칙은 한계에 가장 가까운 구간의 끝이 그 한계를 넘을 때만 플래그를 세우므로, 실제로 상승했더라도 통과할 수 있다. 프롬프트 변경의 메시지 시간이 그 예제이다. 평균은 한계 아래에 있고, 구간의 위쪽 끝은 한계를 넘어선다. 게이트는 그 릴리스가 시간을 한계 너머로 옮겼는지 말할 수 없다. 플래그를 세우지 않는 것밖에 하지 못한다.
넷째는 기록이다. 실제 운영에서는 두 릴리스가 같은 메시지를 만나는 일이 드물며, 실시간 트래픽에서 둘을 비교하는 방법은 LLM 애플리케이션 평가의 트래픽에서의 변형이 다루는 주제이다. 이 장의 모든 릴리스는 책이 기록해 둔 호출의 재생이고, 재생은 그 기록에 담긴 호출에만 응답한다. 다른 호출을 보내는 변경은 응답해 줄 것이 없으므로 여기서 게이트에 걸 수 없다. 같은 곳에서 두 가지 공백이 더 생긴다. 프롬프트 변경의 오류율은 +0.0% (95% interval +0.0% to +0.0%)만큼 변하고, 기준선 자체의 재생에서 실제 ERROR 스팬의 개수는 0인데, 이 상태는 8장에서 설명한다. 오류 규칙은 게이트에 들어 있지만 이 기록들은 그 규칙을 작동시키지 않으므로, 이 장은 게이트가 오류를 잡는 모습을 보여 줄 수 없다. 비용 줄은 책의 가격표에 의존한다. 6장은 자체 호스팅 모델이 토큰이 아니라 기계 단위로 과금된다고 설명하므로, 달러 금액은 토큰 가격을 비교할 뿐 청구서를 비교하지는 않는다.
작업 규칙: 각 게이트의 보고서에 판정과 함께 그 게이트가 읽지 않는 것을 명시하여, 통과를 흠 없는 릴리스로 받아들이지 않도록 한다.
이 장이 내린 결정
- 프롬프트 변경은 짝지은 메시지 60개로, 모델 교체는 200개 전부로, top-8 릴리스와 캐시 끔 릴리스는 각각의 60개로, 평범한 하루는 짝짓지 않은 이틀로 게이트한다. 짝지은 메시지란 기준선과 릴리스가 함께 쓰는 메시지다.
- 한계는 우리가 정한다. 오류 규칙은 8장의 것이다. 이 장은 그 한계를 인쇄된 그대로 적용하며, 이 녹화 데이터에 맞추어 조정하지 않는다.
- 95번째 백분위수는 인쇄만 하고 게이트하지 않으며, 게이트는 메시지 시간의 평균을 판정한다.
- 모델 교체의 양은 접미사와 그것이 잃은 답변으로 나뉘고, 경로 정확도는 모델과 접미사를 합친 것이다. 모델 교체의 비용은 출처 없는 가격 행에 기대고 있으며, 이 장은 비용 줄 옆에 그 사실을 밝혀 둔다.
- 게이트는 실시간 트래픽이 아니라 녹화된 호출을 읽으므로, 여기의 모든 판정은 녹화 데이터를 설명한다.
차이는 구간 없이는 의미가 적고, 같은 메시지를 쓰는 것이 구간을 읽을 만큼 좁게 유지해 준다. 짝지은 메시지 60개에서는 프롬프트 변경의 토큰 차이가 드러난다. 같은 60개를 짝짓지 않고 판정하면 그 차이가 가려진다. 그래서 이 장은 가능한 모든 비교를 짝짓고, 이 게이트를 따라 하는 독자는 한계보다 짝짓기를 먼저 지켜야 한다. 같은 한계라도 짝짓지 않고 판정하면 프롬프트 변경이 통과하기 때문이다.
작업 규칙: 차이는 반드시 구간과 함께, 같은 메시지에서, 게이트의 사각지대를 판정 옆에 인쇄한 채로 읽는다.
이 판의 이 장
2026.11.2판예제 통과 2026년 11월 237 of 7개 예제 in this chapter pass
영어판 2026.11.2판을 번역한 것이다.