2222 pipeline = pipeline .to ("cuda" )
2323 pipeline .precision = "bf16"
2424else :
25- assert args .precision == "int4"
25+ assert args .precision in [ "int4" , "fp4" ]
2626 pipeline_init_kwargs = {}
2727 transformer = NunchakuFluxTransformer2dModel .from_pretrained (
28- "mit-han-lab/nunchaku-flux.1-kontext-dev/svdq-int4_r32 -flux.1-kontext-dev.safetensors"
28+ f "mit-han-lab/nunchaku-flux.1-kontext-dev/svdq-{ args . precision } _r32 -flux.1-kontext-dev.safetensors"
2929 )
3030 pipeline_init_kwargs ["transformer" ] = transformer
3131 if args .use_qencoder :
4040 "black-forest-labs/FLUX.1-Kontext-dev" , torch_dtype = torch .bfloat16 , ** pipeline_init_kwargs
4141 )
4242 pipeline = pipeline .to ("cuda" )
43- pipeline .precision = "int4"
43+ pipeline .precision = args . precision
4444
4545
4646def run (image , prompt : str , num_inference_steps : int , guidance_scale : float , seed : int ) -> tuple [Image , str ]:
@@ -65,17 +65,17 @@ def run(image, prompt: str, num_inference_steps: int, guidance_scale: float, see
6565 latency_str = f"{ latency :.2f} s"
6666 torch .cuda .empty_cache ()
6767 if args .count_use :
68- if os .path .exists (f" { args . model } - use_count.txt" ):
69- with open (f" { args . model } - use_count.txt" , "r" ) as f :
68+ if os .path .exists (" use_count.txt" ):
69+ with open (" use_count.txt" , "r" ) as f :
7070 count = int (f .read ())
7171 else :
7272 count = 0
7373 count += 1
7474 current_time = datetime .now ()
7575 print (f"{ current_time } : { count } " )
76- with open (f" { args . model } - use_count.txt" , "w" ) as f :
76+ with open (" use_count.txt" , "w" ) as f :
7777 f .write (str (count ))
78- with open (f" { args . model } - use_record.txt" , "a" ) as f :
78+ with open (" use_record.txt" , "a" ) as f :
7979 f .write (f"{ current_time } : { count } \n " )
8080 return result_image , latency_str
8181
@@ -91,7 +91,6 @@ def run(image, prompt: str, num_inference_steps: int, guidance_scale: float, see
9191 device_info = f"Running on { gpu_name } with { gpu_memory :.0f} GiB memory."
9292 else :
9393 device_info = "Running on CPU 🥶 This demo does not work on CPU."
94- notice = '<strong>Notice:</strong> We will replace unsafe prompts with a default prompt: "A peaceful world."'
9594
9695 def get_header_str ():
9796
@@ -108,7 +107,9 @@ def get_header_str():
108107 )
109108 else :
110109 count_info = ""
111- header_str = DESCRIPTION .format (device_info = device_info , notice = notice , count_info = count_info )
110+ header_str = DESCRIPTION .format (
111+ precision = args .precision .upper (), device_info = device_info , count_info = count_info
112+ )
112113 return header_str
113114
114115 header = gr .HTML (get_header_str ())
0 commit comments