Skip to content

The Ultimate Guide to Converting Any AI Model to Safetensors

I have previously created a guide on how to convert to .safetensors, and it’s been a bit over a year since I wrote that guide. While the method presented in the old guide is still valid and working, it is a bit of a dirty hack which uses an application built for other purposes to convert the files. The method in this guide is a lot cleaner and doesn’t require anything other than an installation of python together with PyTorch.

Why “Safety First” is More Than a Slogan

Have you ever downloaded a new AI model, excited to try it out, but hesitated for a second? That hesitation is smart. In the world of open-source AI, most models are shared as .ckpt or .pth files, which rely on an old Python technology called “pickle.”

Let’s be honest: pickle files are a security risk. They can contain not just the model’s data, but also executable code. While the community is overwhelmingly amazing, a malicious actor could theoretically hide harmful code inside a model file.

This is why the .safetensors format was created. It’s a newer, more secure standard that can only store the data (the tensors), making it impossible to hide malicious code. As a massive bonus, they also load significantly faster.

Converting your library of models to .safetensors is one of the best things you can do for the security and speed of your AI workflow.

The Problem: A Clunky Conversion Process

So, how do you actually convert these files?

The internet is full of different methods—complex ComfyUI workflows, outdated scripts that only handle one file type, and tools that fail on newer or more complex models. I’ve been down that rabbit hole myself, and it can be frustrating. You just want a simple, reliable tool that works on everything.

After hitting too many dead ends, I decided to build one.

The Solution: A Universal Python Converter Script

I created a simple but powerful Python script designed to be your one-stop shop for model conversion. It’s a single file that can handle virtually any PyTorch-based model you throw at it.

Key Features:

  • Truly Universal: Converts .ckpt, .pth, .pt, and .bin files.
  • Safe By Default: Uses PyTorch’s secure loading methods.
  • “Unsafe” Mode: Includes an optional override for trusted, complex files that require it.
  • Intelligent Parsing: Automatically detects and handles different internal model structures (like state_dict vs. nested model objects).

What You’ll Need
The only thing you need is the Python environment that already comes with your ComfyUI installation. No extra installs required!

How to Use the Converter

This script is run from the command line for maximum speed and efficiency.

  1. Open a Terminal: Open a Command Prompt or PowerShell window.

  2. Navigate to your ComfyUI Folder: Use the cd command. For example: cd C:\AI\Comfy

  3. Run the Conversion: The structure is simple: call ComfyUI’s Python, point to our script, and then give it the path to the model you want to convert. Remember to put the path in quotes if it contains spaces!

Example 1: Converting a .ckpt file – safe mode

For most models, you won’t need any special flags.

.\python_embeded\python.exe safetensor_converter_universal.py "D:\AI_Models\Checkpoints\MyModel.ckpt"

Example 2: Converting a Complex .pt File – Unsafe Mode

For some complex models (like certain face or detection models), you may get a security error. If you trust the source of the file, you can use the –unsafe flag to bypass the security check.

.\python_embeded\python.exe safetensor_converter_universal.py --unsafe "D:\AI_Models\Insightface\MyTrustedModel.pt"

The script will create a new .safetensors file in the exact same folder as the original, leaving the original file untouched.

Take Control of Your Model Library

That’s it. With this one script, you now have a fast, reliable, and universal tool to bring your entire model library up to the modern standard of safety and performance. No more clunky workflows, no more security worries.

Download the python script from my Github: Universal safetensors Converter

Happy (and safe) creating!

All the AI related work I do, I do on my spare time and most of it I share with the world completely free of charge. It does take up a lot of my time, as well as the cost for running this website. So if you do enjoy my work, please consider visiting my Patreon. I offer a few highly customized nodes and guides there, and I’m greatful for every bit of support I can get from users like you.

By signing up on mine and Nova’s newsletter, you will make sure you never miss any important updates.

Published inAIPythonTech