File size: 2,216 Bytes
a84cd10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Cast civitai trained LoRa in torch.bfloat16 to Tensor Art Compatible torch.float16 dtype\n",
        "\n",
        "Created by Adcom: https://tensor.art/u/743241123023077878"
      ],
      "metadata": {
        "id": "YDCnQpDdqDe4"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#initialize\n",
        "import torch\n",
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "metadata": {
        "id": "1oxeJYHRqxQC"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "<---- Upload your civiai trained .safetensor file to Google Colab before running the next cell\n",
        "\n"
      ],
      "metadata": {
        "id": "oDAUwfFzqzgj"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "WQZ3BZn1p-pw"
      },
      "outputs": [],
      "source": [
        "civiai_lora = '' # @param {type:'string' ,placeholder:'ex. civitai_trained_e19.safetensors'}\n",
        "tensor_art_filename = '' # @param {type:'string' ,placeholder:'ex. e19.safetensors'}\n",
        "%cd /content/\n",
        "tgt = load_file(f'{civiai_lora}')\n",
        "for key in tgt:\n",
        "  tgt[f'{key}'] = tgt[f'{key}'].to(dtype=torch.float16)\n",
        "%cd /content/\n",
        "save_file(tgt , f'{tensor_art_filename}')"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "Download the new .safetensor file to your device.\n",
        "\n",
        "Downloading from CoLab Notebook will seemingly do nothing for ~5min. Then the file will download , so be patient.\n",
        "\n",
        "For faster/more consistent downloads , download your .safetensor file from your Google Drive"
      ],
      "metadata": {
        "id": "blnBW-U4rAS7"
      }
    }
  ]
}