Commit 6d28a5c
committed
Fix RecursionError in set_rnd on cyclic object graphs (#8087)
monai.data.utils.set_rnd recursively walks obj.__dict__ to seed randomizable
components. When a dataset holds an OmegaConf/Hydra config (whose child nodes
back-reference their parent), or any object graph with a reference cycle, the
recursion never terminates and raises RecursionError while building a DataLoader
with num_workers=0.
Track visited object ids in an internal _seen set and skip already-visited
objects, breaking the cycle while still seeding every reachable randomizable
component exactly once.
Signed-off-by: Ben Younes <2910651+ousamabenyounes@users.noreply.github.com>1 parent e04a802 commit 6d28a5c
2 files changed
Lines changed: 43 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
689 | | - | |
| 689 | + | |
690 | 690 | | |
691 | 691 | | |
692 | 692 | | |
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
696 | 699 | | |
| 700 | + | |
| 701 | + | |
697 | 702 | | |
698 | 703 | | |
699 | 704 | | |
700 | | - | |
| 705 | + | |
701 | 706 | | |
702 | 707 | | |
703 | 708 | | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
704 | 712 | | |
705 | 713 | | |
706 | 714 | | |
707 | 715 | | |
708 | 716 | | |
709 | 717 | | |
710 | | - | |
| 718 | + | |
711 | 719 | | |
712 | 720 | | |
713 | 721 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
102 | 134 | | |
103 | 135 | | |
0 commit comments