| from safetensors.torch import save_file | |
| import torch | |
| # Load your PyTorch .bin file | |
| # Replace 'path/to/your/pytorch_model.bin' with the actual path | |
| state_dict = torch.load('pytorch_model.bin') | |
| # Define the output path for the .safetensors file | |
| # Replace 'path/to/your/model.safetensors' with your desired output path | |
| output_path = 'model.safetensors' | |
| # Save the state_dict in safetensors format | |
| save_file(state_dict, output_path) | |