mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-07-18 20:38:15 +08:00
torch.randint's high bound is exclusive, so randint(low=0, high=len(ns) - 1) sampled indices 0..len(ns)-2 and never selected the final candidate. With swap_size=2 this always returned the first tile count, silently disabling the node's randomization. Use high=len(ns) so every option is reachable.
23 lines
756 B
Python
23 lines
756 B
Python
from unittest.mock import patch, MagicMock
|
|
|
|
import torch
|
|
|
|
mock_nodes = MagicMock()
|
|
mock_nodes.MAX_RESOLUTION = 16384
|
|
mock_server = MagicMock()
|
|
|
|
with patch.dict("sys.modules", {"nodes": mock_nodes, "server": mock_server}):
|
|
from comfy_extras.nodes_hypertile import random_divisor
|
|
|
|
|
|
class TestRandomDivisor:
|
|
def test_all_options_are_reachable(self):
|
|
# value=8, min=2, max_options=2 -> candidate tile counts {4, 2}; both must be
|
|
# selectable. torch.randint's high is exclusive, so the last option was unreachable.
|
|
torch.manual_seed(0)
|
|
results = {random_divisor(8, 2, 2) for _ in range(200)}
|
|
assert results == {2, 4}
|
|
|
|
def test_single_option_is_deterministic(self):
|
|
assert random_divisor(8, 8, 1) == 1
|