問題文
A monitoring routine appends the current loss to a Python list every iteration by writing history.append(loss). After a few hundred iterations the process runs out of memory. What is the most likely cause and the fix?
選択肢
- The optimizer keeps a copy of every loss it has seen.
- Python lists are documented to copy tensors into a new device allocation each time an element is appended, so the memory grows with the number of appends even when the graph has already been released.
- The stored tensors still reference the graph that produced them, so appending loss.item() instead keeps only the number.
- The loss tensor grows in size every iteration.