Skip to content

Commit 4385ebd

Browse files
committed
mock hf diffuers import
Signed-off-by: Ao Tang <aot@nvidia.com>
1 parent 9a53d8c commit 4385ebd

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

‎tests/unit_tests/diffusion/recipes/flux/test_flux_recipe.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import importlib
16+
from types import SimpleNamespace
17+
1518
import pytest
1619

1720
from megatron.bridge.diffusion.data.flux.flux_energon_datamodule import FluxDatasetConfig
@@ -22,6 +25,46 @@
2225

2326
pytestmark = [pytest.mark.unit]
2427

28+
# Recipe loads HF config via PreTrainedFlux; patch it so unit tests do not call the Hub
29+
# (same idea as test_llama_recipes monkeypatching AutoBridge).
30+
_flux_recipe_mod = importlib.import_module("megatron.bridge.diffusion.recipes.flux.flux")
31+
32+
33+
def _fake_flux_diffusers_config() -> SimpleNamespace:
34+
"""Shape expected by FluxBridge.provider_bridge; values match FLUX.1-dev / recipe defaults."""
35+
return SimpleNamespace(
36+
num_attention_heads=24,
37+
attention_head_dim=128,
38+
in_channels=64,
39+
patch_size=1,
40+
num_layers=19,
41+
num_single_layers=38,
42+
joint_attention_dim=4096,
43+
pooled_projection_dim=768,
44+
guidance_embeds=True,
45+
axes_dims_rope=[16, 56, 56],
46+
ffn_dim=12288,
47+
)
48+
49+
50+
class _FakePreTrainedFlux:
51+
def __init__(self, model_name_or_path, **kwargs):
52+
self._model_name_or_path = str(model_name_or_path)
53+
self._config = _fake_flux_diffusers_config()
54+
55+
@property
56+
def model_name_or_path(self) -> str:
57+
return self._model_name_or_path
58+
59+
@property
60+
def config(self):
61+
return self._config
62+
63+
64+
@pytest.fixture(autouse=True)
65+
def _patch_pretrained_flux_no_hub(monkeypatch: pytest.MonkeyPatch):
66+
monkeypatch.setattr(_flux_recipe_mod, "PreTrainedFlux", _FakePreTrainedFlux)
67+
2568

2669
class TestPretrainConfig:
2770
"""Tests for pretrain_config function (flattened, no-arg API)."""

0 commit comments

Comments
 (0)