shauray commited on
Commit
14989e6
1 Parent(s): e676edc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +73 -4
README.md CHANGED
@@ -1,4 +1,73 @@
1
- ---
2
- license: mit
3
- library_name: diffusers
4
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: diffusers
4
+ ---
5
+ # flux-uncensored-nf4
6
+
7
+ ## Summary
8
+ Flux base model merged with uncensored LoRA, quantized to NF4. This model is not for those looking for "safe" or watered-down outputs. It’s optimized for real-world use with fewer constraints and lower VRAM requirements, thanks to NF4 quantization.
9
+
10
+ ## Specs
11
+ * Model: Flux base
12
+ * LoRA: Uncensored version, merged directly
13
+ * Quantization: NF4 format for speed and VRAM efficiency
14
+
15
+ ## Usage
16
+ Not so much for plug-and-play model, but pretty straight forward (script from sayak [https://github.com/huggingface/diffusers/issues/9165#issue-2462431761])
17
+
18
+ Please install pip install -U bitsandbytes to proceed.
19
+ ```python
20
+ """
21
+ Some bits are from https://github.com/huggingface/transformers/blob/main/src/transformers/modeling_utils.py
22
+ """
23
+
24
+ from huggingface_hub import hf_hub_download
25
+ from accelerate.utils import set_module_tensor_to_device, compute_module_sizes
26
+ from accelerate import init_empty_weights
27
+ from convert_nf4_flux import _replace_with_bnb_linear, create_quantized_param, check_quantized_param
28
+ from diffusers import FluxTransformer2DModel, FluxPipeline
29
+ import safetensors.torch
30
+ import gc
31
+ import torch
32
+
33
+ dtype = torch.bfloat16
34
+ is_torch_e4m3fn_available = hasattr(torch, "float8_e4m3fn")
35
+ ckpt_path = hf_hub_download("shauray/flux.1-dev-uncensored-nf4", filename="diffusion_pytorch_model.safetensors")
36
+ original_state_dict = safetensors.torch.load_file(ckpt_path)
37
+
38
+ with init_empty_weights():
39
+ config = FluxTransformer2DModel.load_config("shauray/flux.1-dev-uncensored-nf4")
40
+ model = FluxTransformer2DModel.from_config(config).to(dtype)
41
+ expected_state_dict_keys = list(model.state_dict().keys())
42
+
43
+ _replace_with_bnb_linear(model, "nf4")
44
+
45
+ for param_name, param in original_state_dict.items():
46
+ if param_name not in expected_state_dict_keys:
47
+ continue
48
+
49
+ is_param_float8_e4m3fn = is_torch_e4m3fn_available and param.dtype == torch.float8_e4m3fn
50
+ if torch.is_floating_point(param) and not is_param_float8_e4m3fn:
51
+ param = param.to(dtype)
52
+
53
+ if not check_quantized_param(model, param_name):
54
+ set_module_tensor_to_device(model, param_name, device=0, value=param)
55
+ else:
56
+ create_quantized_param(
57
+ model, param, param_name, target_device=0, state_dict=original_state_dict, pre_quantized=True
58
+ )
59
+
60
+ del original_state_dict
61
+ gc.collect()
62
+
63
+ print(compute_module_sizes(model)[""] / 1024 / 1204)
64
+
65
+ pipe = FluxPipeline.from_pretrained("black-forest-labs/flux.1-dev", transformer=model, torch_dtype=dtype)
66
+ pipe.enable_model_cpu_offload()
67
+
68
+ prompt = "A mystic cat with a sign that says hello world!"
69
+ image = pipe(prompt, guidance_scale=3.5, num_inference_steps=50, generator=torch.manual_seed(0)).images[0]
70
+ image.save("flux-nf4-dev-loaded.png")
71
+ ```
72
+
73
+ this README has what you'd need, it's a merge from [Uncensored LoRA on CivitAI]([https://civitai.com/models/875879/flux-lustlyai-uncensored-v1-nsfw-lora-with-male-and-female-nudity)