|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
| 15 | +import importlib |
| 16 | +from types import SimpleNamespace |
| 17 | + |
15 | 18 | import pytest |
16 | 19 |
|
17 | 20 | from megatron.bridge.diffusion.data.flux.flux_energon_datamodule import FluxDatasetConfig |
|
22 | 25 |
|
23 | 26 | pytestmark = [pytest.mark.unit] |
24 | 27 |
|
| 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 | + |
25 | 68 |
|
26 | 69 | class TestPretrainConfig: |
27 | 70 | """Tests for pretrain_config function (flattened, no-arg API).""" |
|
0 commit comments