Summary#
컨텍스트 매니저가 네이티브 상태와 Python 상태를 함께 변경하면 본문에서 예외가 발생해도 둘 다 복원되어야 한다. 상태 설정 뒤의 실행과 정리를 try/finally로 감싸고 예외 경로를 테스트한다.
Problem#
DTensor 기본 mesh 컨텍스트는 yield 이후에만 상태를 정리해, 본문에서 예외가 나면 변경된 기본 mesh가 남았다.
Solution#
yield와 정리 코드를 try/finally로 감싸 네이티브 기본 mesh 해제 및 이전 Python 상태 복원을 보장한다.
Failure Modes#
- 예외 이후 상태 누출
- 후속 연산이 잘못된 기본 mesh를 사용
Sources#
- https://github.com/tensorflow/tensorflow/pull/128584
- https://github.com/tensorflow/tensorflow/pull/128997
- https://github.com/tensorflow/tensorflow/pull/129006
- https://github.com/tensorflow/tensorflow/pull/122579
- https://github.com/tensorflow/tensorflow/pull/128969
- https://github.com/tensorflow/tensorflow/pull/128704
- https://github.com/tensorflow/tensorflow/pull/128813
- https://github.com/tensorflow/tensorflow/pull/128967
- https://github.com/tensorflow/tensorflow/pull/126447
- https://github.com/tensorflow/tensorflow/pull/125219
- https://github.com/tensorflow/tensorflow/pull/128657
- https://github.com/huggingface/transformers/pull/49517
- https://github.com/huggingface/transformers/pull/49518
- https://github.com/huggingface/transformers/pull/49598
- https://github.com/huggingface/transformers/pull/49317
- https://github.com/huggingface/transformers/pull/49583
- https://github.com/huggingface/transformers/pull/49568
- https://github.com/huggingface/transformers/pull/47747
- https://github.com/huggingface/transformers/pull/49446
- https://github.com/huggingface/transformers/pull/49543
- https://github.com/huggingface/transformers/pull/49582
- https://github.com/huggingface/transformers/pull/49352
- https://github.com/fastapi/fastapi/pull/16485
- https://github.com/fastapi/fastapi/pull/16484
- https://github.com/fastapi/fastapi/pull/16470
- https://github.com/fastapi/fastapi/pull/16477
- https://github.com/fastapi/fastapi/pull/16476
- https://github.com/fastapi/fastapi/pull/16471
- https://github.com/fastapi/fastapi/pull/16469
- https://github.com/fastapi/fastapi/pull/16468
- https://github.com/fastapi/fastapi/pull/16463
- https://github.com/react/react/pull/37764
- https://github.com/react/react/pull/32499
- https://github.com/react/react/pull/37814
- https://github.com/react/react/pull/31975
- mined_at: 2026-10-14T15:24:07Z
Sagwan Revalidation 2026-10-14T15:56:53Z#
- verdict:
ok - note: 예외 시 상태를 복원하라는 권장안은 여전히 유효하며, 본문에 뚜렷한 모순이 없다.
Sagwan Revalidation 2026-10-17T12:39:11Z#
- verdict:
ok - note: 예외 경로에서도 상태를 복원하는 try/finally 권장안은 유효하며, 본문에 뚜렷한 모순이 없다.
Sagwan Revalidation 2026-10-20T08:06:26Z#
- verdict:
ok - note: 예외 시 상태를 복원하는 try/finally 권장안은 여전히 유효하며, 본문에 뚜렷한 모순이 없다.