한국어
ENN-PyTorch의 커널과 정밀도 계층은 빠른 실행 경로를 우선 시도하되, 실패·비정상 출력·내보내기 제약·자원 부족이 감지되면 안전한 경로로 내려가는 방어형 실행 전략이다.
이 계층은 단순 성능 최적화용 코드가 아니다. Attention backend, Triton kernel, Transformer Engine, PyTorch SDPA, autocast, FP8/BF16/FP32 선택은 모두 모델 forward의 성능과 안정성에 영향을 준다. ENN-PyTorch는 가능한 빠른 backend를 사용하지만, 해당 backend가 실패하거나 nonfinite output을 만들거나 export 상황에서 부적합하면 fallback 경로로 전환한다.
핵심 구조는 다음과 같이 요약할 수 있다.
fast path 시도
→ 실행 조건 검사
→ 실패 또는 nonfinite 감지
→ kernel state 기록
→ safer backend 또는 math fallback
→ 필요 시 autocast 중단 후 master dtype 재시도
이 장의 중심 질문은 “어떤 fast path가 있는가?”가 아니라, “fast path가 안전하지 않을 때 어떤 기준으로 fallback되는가?”다.
English
The kernel and precision layer of ENN-PyTorch is a defensive execution strategy. It tries fast execution paths first, but when failure, abnormal output, export constraints, or resource limitations are detected, it falls back to safer paths.
This layer is not just performance optimization code. Attention backends, Triton kernels, Transformer Engine, PyTorch SDPA, autocast, and FP8/BF16/FP32 choices all affect both the performance and stability of model forward execution. ENN-PyTorch uses fast backends when possible, but switches to fallback paths when those backends fail, produce nonfinite output, or become unsuitable under export conditions.
The core structure can be summarized as follows.
try fast path
→ check execution conditions
→ detect failure or nonfinite output
→ record kernel state
→ use safer backend or math fallback
→ retry with master dtype without autocast when needed
The central question of this chapter is not “Which fast paths exist?” but “By what criteria does execution fall back when a fast path is not safe?”
| 관심사 / Topic | 먼저 볼 섹션 / Recommended Section |
|---|---|
| attention 성능이 기대보다 낮음 | |
| Attention performance is lower than expected | AttentionPolicy, KernelManager, FlexAttention |
| FlexAttention 또는 SDPA가 실제로 쓰이는지 확인하고 싶음 | |
| Need to confirm whether FlexAttention or SDPA is actually used | AttentionPolicy, FlexAttention, DotProductAttention and SDPA Fallback |
| NaN/Inf가 발생함 | |
| NaN or Inf occurs | StatelessAutocast, StatefulAutocast, Precision Execution Strategy |
| BF16 예측 결과가 지나치게 비슷함 | |
| BF16 prediction results are too similar | fp32 prediction tail guard |
| export가 실패함 | |
| Export fails | Fallback at Export Boundaries |
| 환경변수로 실행 경로를 조정하고 싶음 | |
| Need to adjust execution paths with environment variables | Main Environment Variable Categories, C. Operational Configuration Reference |
한국어
커널과 정밀도 계층은 모델 forward 내부에서 dtype, device, attention call site, compile/export 상태를 함께 보고 실행 경로를 선택한다. 커널 선택과 정밀도 선택은 분리되어 있지 않다. 같은 attention layer라도 device, dtype, mask, compile 상태, export 상태에 따라 실행 경로가 달라질 수 있다.