Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Import a safetensors binary file
ResourceFunction["ImportSafetensors"][file] returns an Association with tensors from a safetensors binary file. | |
ResourceFunction["ImportSafetensors"][file,name] returns a specific tensor with the given name. | |
ResourceFunction["ImportSafetensors"][file,{name1,name2,…}] returns multiple tensors. | |
ResourceFunction["ImportSafetensors"][file,"Header"] returns a header containing each tensor's type, dimensions and offset. |
Import tensors from the wild:
| In[1]:= |
| Out[1]= | ![]() |
Import a single tensor:
| In[2]:= |
| Out[2]= | ![]() |
Import just a header:
| In[3]:= |
| Out[3]= | ![]() |
Missing tensors are reported and ignored:
| In[4]:= |
| Out[4]= |
Import DreamShaper weights:
| In[5]:= |
Use the imported tensors to modify Stable Diffusion V1 parts:
| In[6]:= | ![]() |
Define a function to modify networks:
| In[7]:= | ![]() |
Create a modified encoder, unet and decoder:
| In[8]:= | ![]() |
Compare vanilla and modified weights. These evaluations may take several minutes (unless GPU is available):
| In[9]:= |
| Out[9]= | ![]() |
| In[10]:= | ![]() |
| Out[10]= | ![]() |
Add more details using LoRA (Low-Rank Adaptation), with small adjustments to existing model weights. Define a collection of utility functions to help:
| In[11]:= | ![]() |
Apply the weights using the utility functions:
| In[12]:= | ![]() |
Generate new images with weights modified using LoRA technique:
| In[13]:= | ![]() |
| Out[14]= | ![]() |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License