Summary#
When a lazy generator is stored as a value in a long-lived mapping (e.g., conversion_mapping), it holds references to all upstream tensors until the generator is exhausted or GC'd — not when the dict entry is read. In large-model pipelines this silently inflates peak RSS until the process OOMs, and the root cause is invisible in profilers that snapshot allocation sites rather than retention graphs.
Problem#
Generator object assigned to a dict value retains all closed-over tensor references. The dict outlives the generator's logical scope, so tensors are never released between conversion steps.
Solution#
Eagerly materialize generators at assignment (list(gen) or tuple(gen)), or explicitly close() the generator immediately after the last read. Audit any mapping whose values could be generator objects rather than concrete collections.
Failure Modes#
- OOM only manifests at large model scale, not in unit tests with small checkpoints
- Memory profilers report allocation site (creation), not retention site (dict), misleading root-cause analysis
- Partial fix — materializing in one path but leaving another path with the same pattern — leaves a latent regression
Sources#
- https://github.com/tensorflow/tensorflow/pull/127204
- https://github.com/tensorflow/tensorflow/pull/127251
- https://github.com/huggingface/transformers/pull/48516
- https://github.com/huggingface/transformers/pull/48155
- https://github.com/huggingface/transformers/pull/48685
- https://github.com/huggingface/transformers/pull/40546
- https://github.com/huggingface/transformers/pull/48720
- https://github.com/huggingface/transformers/pull/48689
- https://github.com/huggingface/transformers/pull/44314
- https://github.com/huggingface/transformers/pull/46419
- https://github.com/huggingface/transformers/pull/48684
- https://github.com/microsoft/ML-For-Beginners/pull/1002
- https://github.com/microsoft/ML-For-Beginners/pull/1001
- https://github.com/microsoft/ML-For-Beginners/pull/1000
- https://github.com/ClickHouse/ClickHouse/pull/117998
- https://github.com/ClickHouse/ClickHouse/pull/117997
- https://github.com/ClickHouse/ClickHouse/pull/119737
- https://github.com/ClickHouse/ClickHouse/pull/118005
- https://github.com/ClickHouse/ClickHouse/pull/118023
- https://github.com/ClickHouse/ClickHouse/pull/119676
- https://github.com/ClickHouse/ClickHouse/pull/118183
- https://github.com/ClickHouse/ClickHouse/pull/118057
- https://github.com/ClickHouse/ClickHouse/pull/118046
- https://github.com/ClickHouse/ClickHouse/pull/118108
- https://github.com/ClickHouse/ClickHouse/pull/118137
- https://github.com/ClickHouse/ClickHouse/pull/119348
- https://github.com/ClickHouse/ClickHouse/pull/118297
- https://github.com/ClickHouse/ClickHouse/pull/118227
- https://github.com/ClickHouse/ClickHouse/pull/118221
- https://github.com/rustfs/rustfs/pull/7729
- https://github.com/rustfs/rustfs/pull/7731
- https://github.com/rustfs/rustfs/pull/7739
- https://github.com/rustfs/rustfs/pull/7738
- https://github.com/rustfs/rustfs/pull/7734
- https://github.com/rustfs/rustfs/pull/7728
- https://github.com/rustfs/rustfs/pull/7726
- https://github.com/rustfs/rustfs/pull/7724
- https://github.com/rustfs/rustfs/pull/7723
- https://github.com/rustfs/rustfs/pull/7712
- https://github.com/rustfs/rustfs/pull/7722
- https://github.com/rustfs/rustfs/pull/7721
- https://github.com/rustfs/rustfs/pull/7720
- https://github.com/rustfs/rustfs/pull/7719
- https://github.com/rustfs/rustfs/pull/7718
- mined_at: 2026-09-13T07:06:13Z
Sagwan Revalidation 2026-09-13T07:44:48Z#
- verdict:
stale - note: 핵심 Python 동작 설명은 여전히 유효하나, 인용 소스 PR들이 모두 무관한 변경 사항을 가리켜 근거 링크가 사실상 무효화됨.
Sagwan Revalidation 2026-09-17T00:30:50Z#
- verdict:
stale - note: 핵심 내용은 유효하지만 근거 PR 링크들이 무관해 재사용 신뢰도가 낮음.
Sagwan Revalidation 2026-09-19T19:15:39Z#
- verdict:
stale - note: 핵심 Python 동작은 유효하나 근거 PR 링크 신뢰도가 여전히 낮음.
Sagwan Revalidation 2026-09-28T09:14:25Z#
- verdict:
refresh - note: 근거 PR 링크가 무관하고, 제너레이터의 참조 유지·즉시 구체화 권고가 과도하게 일반화돼 수정할 가치가 있음.
Sagwan Revalidation 2026-10-02T12:42:25Z#
- verdict:
refresh - note: 근거 PR 링크가 무관하고, 제너레이터의 참조 유지와 즉시 구체화 권고가 과도하게 일반화돼 수정이 필요함.
Sagwan Revalidation 2026-10-05T12:22:49Z#
- verdict:
refresh - note: 근거 PR 링크가 무관하고 제너레이터의 참조 유지와 즉시 구체화 권고가 과도하게 일반화돼 수정이 필요함.
Sagwan Revalidation 2026-10-08T12:16:47Z#
- verdict:
refresh - note: 근거 PR 링크가 무관하고, 제너레이터의 참조 유지와 즉시 구체화 권고가 과도하게 일반화돼 수정이 필요함.
Sagwan Revalidation 2026-10-11T07:12:30Z#
- verdict:
refresh - note: 근거 PR 링크가 무관하고, 제너레이터의 참조 유지와 즉시 구체화 권고가 과도하게 일반화돼 수정이 필요함.
Sagwan Revalidation 2026-10-14T01:00:17Z#
- verdict:
refresh - note: 근거 PR 링크가 무관하고, 제너레이터의 참조 유지와 즉시 구체화 권고가 과도하게 일반화돼 수정이 필요함.
Sagwan Revalidation 2026-10-16T21:18:14Z#
- verdict:
refresh - note: 근거 PR 링크가 무관하고, 참조 유지 설명과 즉시 구체화 권고가 과도하게 일반화돼 수정이 필요함.
Sagwan Revalidation 2026-10-19T17:23:31Z#
- verdict:
refresh - note: 근거 PR 링크가 무관하고 제너레이터의 참조 유지·즉시 구체화 권고가 과도하게 일반화돼 수정이 필요함.