Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion train_second.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# load packages
import copy
import os
import random
import yaml
import time
from munch import Munch
import numpy as np
import torch

torch.autograd.set_detect_anomaly(True)
# Anomaly detection is a debugging tool — it traces every op in the autograd
# graph to surface NaN/inf sources, but it makes backward 5–10× slower, holds
# extra memory (causes OOMs that wouldn't otherwise happen), and on some
# single-GPU + bf16 setups it deadlocks the first backward pass entirely.
# Off by default; opt in via STYLETTS2_DETECT_ANOMALY=1 when diagnosing.
if os.environ.get("STYLETTS2_DETECT_ANOMALY") == "1":
torch.autograd.set_detect_anomaly(True)

if getattr(torch, "_original_load", None) is None:
torch._original_load = torch.load
Expand Down