Disty0 commited on
Commit
55d4a6a
·
verified ·
1 Parent(s): 5d60ae9

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +51 -0
README.md ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model:
4
+ - zai-org/GLM-Image
5
+ base_model_relation: quantized
6
+ library_name: diffusers
7
+ tags:
8
+ - sdnq
9
+ - 4-bit
10
+ - glm-image
11
+ ---
12
+ Dynamic 4 bit quantization of [zai-org/GLM-Image](https://huggingface.co/zai-org/GLM-Image) using [SDNQ](https://github.com/vladmandic/sdnext/wiki/SDNQ-Quantization).
13
+
14
+ This model uses per layer fine grained quantization.
15
+ What dtype to use for a layer is selected dynamically by trial and error until the std normalized mse loss is lower than the selected threshold.
16
+
17
+ Minimum allowed dtype is set to uint4 and std normalized mse loss threshold is set to 1e-2.
18
+ This created a mixed precision model with uint4, int5 and float5_e3m1fn dtypes.
19
+ SVD quantization is disabled.
20
+
21
+ Usage:
22
+ ```
23
+ pip install sdnq
24
+ ```
25
+
26
+ ```py
27
+ import torch
28
+ import diffusers
29
+ from sdnq import SDNQConfig # import sdnq to register it into diffusers and transformers
30
+ from sdnq.common import use_torch_compile as triton_is_available
31
+ from sdnq.loader import apply_sdnq_options_to_model
32
+
33
+ pipe = diffusers.GlmImagePipeline.from_pretrained("zai-org/GLM-Image", torch_dtype=torch.bfloat16, device_map="cuda")
34
+
35
+ # Enable INT8 MatMul for AMD, Intel ARC and Nvidia GPUs:
36
+ if triton_is_available and (torch.cuda.is_available() or torch.xpu.is_available()):
37
+ pipe.transformer = apply_sdnq_options_to_model(pipe.transformer, use_quantized_matmul=True)
38
+ # pipe.transformer = torch.compile(pipe.transformer) # optional for faster speeds
39
+
40
+ prompt = "A beautifully designed modern food magazine style dessert recipe illustration, themed around a raspberry mousse cake. The overall layout is clean and bright, divided into four main areas: the top left features a bold black title 'Raspberry Mousse Cake Recipe Guide', with a soft-lit close-up photo of the finished cake on the right, showcasing a light pink cake adorned with fresh raspberries and mint leaves; the bottom left contains an ingredient list section, titled 'Ingredients' in a simple font, listing 'Flour 150g', 'Eggs 3', 'Sugar 120g', 'Raspberry puree 200g', 'Gelatin sheets 10g', 'Whipping cream 300ml', and 'Fresh raspberries', each accompanied by minimalist line icons (like a flour bag, eggs, sugar jar, etc.); the bottom right displays four equally sized step boxes, each containing high-definition macro photos and corresponding instructions, arranged from top to bottom as follows: Step 1 shows a whisk whipping white foam (with the instruction 'Whip egg whites to stiff peaks'), Step 2 shows a red-and-white mixture being folded with a spatula (with the instruction 'Gently fold in the puree and batter'), Step 3 shows pink liquid being poured into a round mold (with the instruction 'Pour into mold and chill for 4 hours'), Step 4 shows the finished cake decorated with raspberries and mint leaves (with the instruction 'Decorate with raspberries and mint'); a light brown information bar runs along the bottom edge, with icons on the left representing 'Preparation time: 30 minutes', 'Cooking time: 20 minutes', and 'Servings: 8'. The overall color scheme is dominated by creamy white and light pink, with a subtle paper texture in the background, featuring compact and orderly text and image layout with clear information hierarchy."
41
+ image = pipe(
42
+ prompt=prompt,
43
+ height=32 * 32,
44
+ width=36 * 32,
45
+ num_inference_steps=50,
46
+ guidance_scale=1.5,
47
+ generator=torch.manual_seed(42),
48
+ ).images[0]
49
+
50
+ image.save("output_t2i-sdnq.png")
51
+ ```