1+ import json
2+ import os
3+ import yaml
4+
5+ from .. import pyconfig
6+ from ..configuration_utils import ConfigMixin
7+ from .. import __version__
8+
9+ class DummyConfigMixin (ConfigMixin ):
10+ config_name = "config.json"
11+
12+ def __init__ (self , ** kwargs ):
13+ self .register_to_config (** kwargs )
14+
15+ def test_to_json_string_with_config ():
16+ # Load the YAML config file
17+ config_path = os .path .join (os .path .dirname (__file__ ), ".." , "configs" , "base_wan_14b.yml" )
18+
19+ # Initialize pyconfig with the YAML config
20+ pyconfig .initialize ([None , config_path ])
21+ config = pyconfig .config
22+
23+ # Create a DummyConfigMixin instance
24+ dummy_config = DummyConfigMixin (** config .get_keys ())
25+
26+ # Get the JSON string
27+ json_string = dummy_config .to_json_string ()
28+
29+ # Parse the JSON string
30+ parsed_json = json .loads (json_string )
31+
32+ # Assertions
33+ assert parsed_json ["_class_name" ] == "DummyConfigMixin"
34+ assert parsed_json ["_diffusers_version" ] == __version__
35+
36+ # Check a few values from the config
37+ assert parsed_json ["run_name" ] == config .run_name
38+ assert parsed_json ["pretrained_model_name_or_path" ] == config .pretrained_model_name_or_path
39+ assert parsed_json ["flash_block_sizes" ]["block_q" ] == config .flash_block_sizes ["block_q" ]
40+
41+ # The following keys are explicitly removed in to_json_string, so we assert they are not present
42+ assert "weights_dtype" not in parsed_json
43+ assert "precision" not in parsed_json
0 commit comments