[pytorch] CI: Inductor 테스트에 IoU 기반 accuracy 체크를 추가하여 segmentation 모델 안정화
PR 링크: pytorch/pytorch#172063 상태: Merged | 변경: +40 / -1
들어가며
Segmentation 모델(SAM, Mask R-CNN 등)의 출력은 boolean mask입니다. 기존 accuracy 체크는 boolean 텐서에 대해 정확한 일치(exact match)를 요구했는데, Inductor의 컴파일 결과에서 부동소수점 수준의 미세한 차이가 threshold를 넘나들면서 boolean mask가 달라지는 false failure가 빈번했습니다. 이 PR은 boolean mask 비교에 IoU(Intersection over Union) 메트릭을 도입하여 이 문제를 해결합니다.
핵심 코드 분석
1. IoU 비교 로직 추가 (utils.py)
same() 함수의 boolean 텐서 처리 부분에 IoU 로직이 추가되었습니다.
Before:
if ref.dtype == torch.bool:
if ignore_non_fp:
return True
# 정확한 일치만 허용
r = torch.allclose(
ref.to(dtype=torch.uint8),
res.to(dtype=torch.uint8), ...
)
After:
if ref.dtype == torch.bool:
if ignore_non_fp:
return True
if use_iou_for_bool:
intersection = (ref & res).sum().float()
union = (ref | res).sum().float()
if union == 0:
return bool(intersection == 0)
iou = (intersection / union).item()
iou_threshold = 0.99
if iou < iou_threshold:
log_error("IoU accuracy failed: %.4f < %.2f", iou, iou_threshold)
return False
return True
# 기존 exact match 로직
IoU는 두 mask의 교집합을 합집합으로 나눈 값으로, 1.0이면 완벽히 일치하고 0.0이면 전혀 겹치지 않습니다. threshold를 0.99로 설정하여 1% 미만의 차이는 허용합니다.
2. 모델별 IoU 적용 설정 (torchbench.yaml)
# Models with boolean mask outputs that should use IoU
use_iou_for_bool_masks:
- sam
- sam_fast
- vision_maskrcnn
모든 모델에 IoU를 적용하는 대신, segmentation 출력을 가진 모델에만 선택적으로 적용합니다.
3. sam_fast를 non_deterministic에서 제거
non_deterministic:
- mobilenet_v3_large
# sam_fast 제거됨 (IoU로 해결)
기존에는 sam_fast를 non-deterministic으로 분류하여 accuracy 체크를 건너뛰었지만, IoU 도입으로 정상적인 accuracy 검증이 가능해졌습니다.
왜 이게 좋은가
segmentation 모델에서 sigmoid(x) > 0.5와 같은 threshold 연산은 경계값 근처에서 부동소수점 오차에 민감합니다. 예를 들어 sigmoid(0.000001)과 sigmoid(-0.000001)은 수학적으로 거의 동일하지만, 하나는 True, 다른 하나는 False가 됩니다. exact match는 이를 100% 불일치로 판정하지만, IoU는 전체 mask에서 얼마나 일치하는지를 측정하므로 실질적인 정확도를 반영합니다. 0.99 threshold는 mask 픽셀의 99%가 일치해야 통과하므로 충분히 엄격합니다.
정리
- boolean mask 비교에 IoU 메트릭 도입 (threshold 0.99)
- SAM, sam_fast, vision_maskrcnn 3개 segmentation 모델에 적용
- sam_fast를 non_deterministic에서 제거하여 정상적인 accuracy 체크 복원
same()함수에use_iou_for_bool파라미터를 재귀적으로 전파
참고 자료
⚠️ 알림: 이 분석은 AI가 실제 코드 diff를 기반으로 작성했습니다.
관련 포스트
PR Analysis 의 다른글
- 이전글 [Triton] ReduceOp 로우어링을 LinearLayout 기반으로 개선 및 단순화
- 현재글 : [pytorch] CI: Inductor 테스트에 IoU 기반 accuracy 체크를 추가하여 segmentation 모델 안정화
- 다음글 [triton] AMD: padded shared layout을 더 작은 block size에도 적용하여 bank conflict 제거
댓글