This script merges multiple sharded .safetensors files into a single safetensors file.
It is useful if you have a model split into parts (such as model-00001-of-00003.safetensors, model-00002-of-00003.safetensors, etc.) and want to reconstruct the full model.
- Python 3.7 or later
- Safetensors
- NumPy 1.x (2.x may not work)
- Clone or download this repository.
- Setup virtual environment (recommended):
python -m venv venv venv/Scripts/activate.bat or ./venv/Scripts/Activate.ps1
- Install dependencies:
pip install -r requirements.txt
- Place all your
.safetensorsshard files in the 'shards' folder. - Run the script:
python merge.py or python ./merge.py
- The merged file (e.g., merged_model.safetensors) will be created in 'output' folder.
- Check for metadata:
python stripmetadata.py your_model.safetensors
- To remove metadata:
python stripmetadata.py --strip your_model.safetensors
- The your_model_stripped.safetensors model is saved with no metadata in the same folder.
Make sure you have enough disk space for the conversion.
- FP32 to BF16:
python convertFP32toBF16.py your_model.safetensors
- BF16 to FP32:
python convertBF16toFP32.py your_model.safetensors
python convert2safetensors.py your_model.pth
Suppose you have these files:
model-00001-of-00003.safetensors
model-00002-of-00003.safetensors
model-00003-of-00003.safetensors
You’ll get:
merged_model.safetensors