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]= | ![]() |
Import DreamShaper weights (downloading manually first is faster for large files):
In[4]:= | ![]() |
Use the imported tensors to modify Stable Diffusion V1 parts:
In[5]:= | ![]() |
Define a function to modify networks:
In[6]:= | ![]() |
Create a modified encoder, unet and decoder:
In[7]:= | ![]() |
Compare vanilla and modified weights. These evaluations may take several minutes:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
Add more details using LoRA (Low-Rank Adaptation), with small adjustments to existing model weights. Define a collection of utility functions to help:
In[10]:= | ![]() |
Apply the weights using the utility functions:
In[11]:= | ![]() |
Generate new images with weights modified using LoRA technique:
In[12]:= | ![]() |
Out[12]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License