MegaTronX commited on
Commit
1ac39da
·
verified ·
1 Parent(s): ef53488

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import FluxPipeline
4
+
5
+ # Function to load the model and list layers
6
+ def list_flux_layers():
7
+ try:
8
+ # Load the FLUX.1-dev model
9
+ # Using torch.bfloat16 to reduce memory usage, offloading to CPU if needed
10
+ pipe = FluxPipeline.from_pretrained(
11
+ "black-forest-labs/FLUX.1-dev",
12
+ torch_dtype=torch.bfloat16
13
+ )
14
+ pipe.enable_model_cpu_offload() # Offload to CPU to save VRAM
15
+
16
+ # Access the transformer (main component of Flux) and get layer names
17
+ model = pipe.transformer # Flux's core transformer model
18
+ layer_names = []
19
+
20
+ # Iterate through all named modules to get layer names
21
+ for name, module in model.named_modules():
22
+ layer_names.append(name)
23
+
24
+ # Format the output as a numbered list
25
+ output = "\n".join([f"{i+1}. {name}" for i, name in enumerate(layer_names)])
26
+ return f"Layers of FLUX.1-dev:\n\n{output}"
27
+ except Exception as e:
28
+ return f"Error loading model or listing layers: {str(e)}"
29
+
30
+ # Create Gradio interface
31
+ with gr.Blocks(title="FLUX.1-dev Layer Lister") as demo:
32
+ gr.Markdown("# FLUX.1-dev Layer Lister")
33
+ gr.Markdown("Click the button below to list all layers in the black-forest-labs/FLUX.1-dev model.")
34
+
35
+ # Button to trigger the layer listing
36
+ btn = gr.Button("List Layers")
37
+
38
+ # Output area for the layer names
39
+ output = gr.Textbox(label="Model Layers", lines=20, placeholder="Layer names will appear here...")
40
+
41
+ # Connect the button to the function
42
+ btn.click(fn=list_flux_layers, inputs=None, outputs=output)
43
+
44
+ # Launch the app
45
+ demo.launch()