Skip to content

Commit fb2e6fe

Browse files
committed
fix: resolve NaN issue in fushh7_llmdet_swin_tiny_hf and improve code formatting
- Replaced -inf with -1e6 in fushh7_llmdet_swin_tiny_hf/model.py (same fix as IDEA-Research_grounding-dino-base) - Improved code formatting in utils.py (removed trailing spaces, better line breaks) - Both nope and inductor backends now pass without NaN for this sample
1 parent 7c359b7 commit fb2e6fe

File tree

2 files changed

+16
-15
lines changed
  • graph_net/torch
  • samples/transformers-auto-model/fushh7_llmdet_swin_tiny_hf

2 files changed

+16
-15
lines changed

graph_net/torch/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,13 @@ def replay_tensor(info):
300300
if "max_val" in info["info"]:
301301
max_val = info["info"]["max_val"]
302302
tensor = torch.clamp(tensor, max=max_val)
303-
303+
304304
# Additional numerical stability checks
305305
if dtype.is_floating_point:
306306
# Replace any inf or nan values with small random values
307-
tensor = torch.where(torch.isfinite(tensor), tensor,
308-
torch.randn_like(tensor) * 0.01)
307+
tensor = torch.where(
308+
torch.isfinite(tensor), tensor, torch.randn_like(tensor) * 0.01
309+
)
309310
# Ensure no extremely large values
310311
tensor = torch.clamp(tensor, min=-100.0, max=100.0)
311312

samples/transformers-auto-model/fushh7_llmdet_swin_tiny_hf/model.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ def forward(
106106
bool_1 = None
107107
invert = ~getitem_1
108108
getitem_1 = None
109-
output_1 = output.masked_fill(invert, -inf)
109+
output_1 = output.masked_fill(invert, -1e6)
110110
output = invert = None
111111
new_output = torch.full(
112-
(1, 900, 256), -inf, device=device(type="cuda", index=0)
112+
(1, 900, 256), -1e6, device=device(type="cuda", index=0)
113113
)
114114
new_output[(Ellipsis, slice(None, 7, None))] = output_1
115115
setitem = new_output
@@ -155,10 +155,10 @@ def forward(
155155
bool_2 = None
156156
invert_1 = ~getitem_5
157157
getitem_5 = None
158-
output_3 = output_2.masked_fill(invert_1, -inf)
158+
output_3 = output_2.masked_fill(invert_1, -1e6)
159159
output_2 = invert_1 = None
160160
new_output_1 = torch.full(
161-
(1, 900, 256), -inf, device=device(type="cuda", index=0)
161+
(1, 900, 256), -1e6, device=device(type="cuda", index=0)
162162
)
163163
new_output_1[(Ellipsis, slice(None, 7, None))] = output_3
164164
setitem_1 = new_output_1
@@ -204,10 +204,10 @@ def forward(
204204
bool_3 = None
205205
invert_2 = ~getitem_9
206206
getitem_9 = None
207-
output_5 = output_4.masked_fill(invert_2, -inf)
207+
output_5 = output_4.masked_fill(invert_2, -1e6)
208208
output_4 = invert_2 = None
209209
new_output_2 = torch.full(
210-
(1, 900, 256), -inf, device=device(type="cuda", index=0)
210+
(1, 900, 256), -1e6, device=device(type="cuda", index=0)
211211
)
212212
new_output_2[(Ellipsis, slice(None, 7, None))] = output_5
213213
setitem_2 = new_output_2
@@ -253,10 +253,10 @@ def forward(
253253
bool_4 = None
254254
invert_3 = ~getitem_13
255255
getitem_13 = None
256-
output_7 = output_6.masked_fill(invert_3, -inf)
256+
output_7 = output_6.masked_fill(invert_3, -1e6)
257257
output_6 = invert_3 = None
258258
new_output_3 = torch.full(
259-
(1, 900, 256), -inf, device=device(type="cuda", index=0)
259+
(1, 900, 256), -1e6, device=device(type="cuda", index=0)
260260
)
261261
new_output_3[(Ellipsis, slice(None, 7, None))] = output_7
262262
setitem_3 = new_output_3
@@ -302,10 +302,10 @@ def forward(
302302
bool_5 = None
303303
invert_4 = ~getitem_17
304304
getitem_17 = None
305-
output_9 = output_8.masked_fill(invert_4, -inf)
305+
output_9 = output_8.masked_fill(invert_4, -1e6)
306306
output_8 = invert_4 = None
307307
new_output_4 = torch.full(
308-
(1, 900, 256), -inf, device=device(type="cuda", index=0)
308+
(1, 900, 256), -1e6, device=device(type="cuda", index=0)
309309
)
310310
new_output_4[(Ellipsis, slice(None, 7, None))] = output_9
311311
setitem_4 = new_output_4
@@ -354,10 +354,10 @@ def forward(
354354
bool_6 = None
355355
invert_5 = ~getitem_21
356356
getitem_21 = None
357-
output_11 = output_10.masked_fill(invert_5, -inf)
357+
output_11 = output_10.masked_fill(invert_5, -1e6)
358358
output_10 = invert_5 = None
359359
new_output_5 = torch.full(
360-
(1, 900, 256), -inf, device=device(type="cuda", index=0)
360+
(1, 900, 256), -1e6, device=device(type="cuda", index=0)
361361
)
362362
new_output_5[(Ellipsis, slice(None, 7, None))] = output_11
363363
setitem_5 = new_output_5

0 commit comments

Comments
 (0)