make code that takes 2 safetensors models and adds weights that not exists in another so…
- User
make code that takes 2 safetensors models and adds weights that not exists in another so in result i have models that has both weights
- Assistant
To combine two models with weights not present in one model into another, you can create a new model that encompasses the weights of both models. Below, I'll provide a Python script using the library for handling tensor serialization. This script will load the tensor weights from two models and combine them such that the result contains all unique weights from both models.
- User
make it save in fp16
- Assistant
To save the combined model in FP16 (half-precision floating point) format, you need to ensure that the tensor data is cast to
torch.float16before saving. Here's how you can modify the script to do this:import torch from safetensors.torch import load_file, save_file def combine_safetensors_models_fp16(model1_path, model2_path, output_path): # Load both models model1 = load_file(model1_path) model2 = load_file(model2_path) # Create a new dictionary to store the combined weights combined_model = {} # Add weights from the first model, converting them to FP16 for key, value in model1.items(): combined_model[key] = value.to(torch.float16) # Add weights from the second model if they do not exist in the first, converting to FP16 for key, value in model2.items(): if key not in combined_model: combined_model[key] = value.to(torch.float16) # Save the combined weights to a new safetensors file, using FP16 save_file(combined_model, output_path) # Example usage: Replace 'model1.safetensors', 'model2.safetensors', and 'combined_model_fp16.safetensors' # with your actual file paths combine_safetensors_models_fp16('model1.safetensors', 'model2.safetensors', 'combined_model_fp16.safetensors') - User
still fp32
- Assistant
- User
put_blocks.8.1.transformer_blocks.8.attn2.to_k.weight model.diffusion_model.input_blocks.8.1.transformer_blocks.8.attn2.to_out.0.bias model.diffusion_model.input_blocks.8.1.transformer_blocks.8.attn2.to_out.0.weight model.diffusion_model.input_blocks.8.1.transformer_blocks.8.attn2.to_q.weight model.diffusion_model.input_blocks.8.1.transformer_blocks.8.attn2.to_v.weight model.diffusion_model.input_blocks.8.1.transformer_blocks.8.ff.net.0.proj.bias model.diffusion_model.input_blocks.8.1.transformer_blocks.8.ff.net.0.proj.weight model.diffusion_model.input_blocks.8.1.transformer_blocks.8.ff.net.2.bias model.diffusion_model.input_blocks.8.1.transformer_blocks.8.ff.net.2.weight model.diffusion_model.input_blocks.8.1.transformer_blocks.8.norm1.bias model.diffusion_model.input_blocks.8.1.transformer_blocks.8.norm1.weight model.diffusion_model.input_blocks.8.1.transformer_blocks.8.norm2.bias model.diffusion_model.input_blocks.8.1.transformer_blocks.8.norm2.weight model.diffusion_model.input_blocks.8.1.transformer_blocks.8.norm3.bias model.diffusion_model.input_blocks.8.1.transformer_blocks.8.norm3.weight model.diffusion_model.input_blocks.8.1.transformer_blocks.9.attn1.to_k.weight model.diffusion_model.input_blocks.8.1.transformer_blocks.9.attn1.to_out.0.bias
what is 8.1
- Assistant
In the context of neural network architectures, particularly those dealing with complex models like diffusion models or transformers, notation such as
8.1typically refers to hierarchical indexing within a nested model component.Here's how to interpret
8.1:-
Hierarchical or Layered Structures: Many deep learning models are composed of blocks or layers that themselves contain further sub-layers or components. The notation
8.1often indicates:- 8: Refers to the 9th parent block or layer (assuming zero-based indexing).
-
- User
make it so the model have same naming because now models contains same weight but with different naming and program work not properly
- Assistant