[CRASH CONDITION] - Critical Bug - Uninitialized last_id Variable
- Dominant language
- Python
- Stars
- 14.3k
- Forks
- 3.1k
- PR merge metrics
- No merged PRs in 30d
Description
## `last_id` is only assigned within the `else` branch when _**`len(type_nids) > 0`**_
https://github.com/dmlc/dgl/blob/3d16000b4170fa741ed9e9667f22ba84d3493026/tools/distpartitioning/convert_partition.py#L546-L557
**When it fails:** When a partition contains zero nodes across ALL node types - which is exactly what this commit is trying to support for "graphs with few nodes/edges". Below line will result in crash -
https://github.com/dmlc/dgl/blob/3d16000b4170fa741ed9e9667f22ba84d3493026/tools/distpartitioning/convert_partition.py#L564
## Fix:
```python
# tools/distpartitioning/convert_partition.py
#...
# FIX 1: Track the max ID in a regular integer variable first.
max_last_id = prev_last_id
for ntype_name in global_nid_ranges:
#...
if len(type_nids) > 0:
node_map_val[ntype_name].append(
[int(type_nids[0]), int(type_nids[-1]) + 1]
)
# FIX 2: Correctly update the running maximum ID.
current_last_id = int(type_nids[-1]) + 1
if current_last_id > max_last_id:
max_last_id = current_last_id
else:
node_map_val[ntype_name].append([-1, -1])
# FIX 3: Create the tensor *after* the loop with the correct maximum value.
last_id = th.tensor([max_last_id], dtype=th.int64)
dist.all_gather(gather_last_ids, last_id)`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.