{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "2590bea3-bcfc-4630-8393-2c4762cb4168", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/data/dell/anaconda3/envs/torch1.8/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "import torch\n", "import joblib\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "id": "4c433f59-b8bf-47c3-9bf0-f3ca8f7a0e6c", "metadata": {}, "outputs": [], "source": [ "with open('torch_weights.txt', 'r') as f:\n", " lines = f.readlines()\n", "tkeys = [iline.strip() for iline in lines]" ] }, { "cell_type": "code", "execution_count": 3, "id": "ab6977f5-2593-4dd2-9a3c-d72124ce7060", "metadata": {}, "outputs": [], "source": [ "with open('jax_weights.txt', 'r') as f:\n", " lines = f.readlines()\n", "jkeys = [iline.strip() for iline in lines]" ] }, { "cell_type": "code", "execution_count": 4, "id": "67989df7-409e-43e9-8af9-6a21f0aef483", "metadata": {}, "outputs": [], "source": [ "# directory for jax and pytorch weights\n", "weight_dir = '/data/dell/Desktop/GitHub/ProteinMPNN_jax/weights/torch'\n", "dest_dir = '/data/dell/Desktop/GitHub/ProteinMPNN_jax/weights/jax'" ] }, { "cell_type": "code", "execution_count": 5, "id": "c786705d-240b-4bb6-a767-adee16c501f8", "metadata": {}, "outputs": [], "source": [ "weight_list = [\"v_48_010\", \"v_48_020\"]" ] }, { "cell_type": "code", "execution_count": 14, "id": "b264f1d9-dab7-4f69-9486-9bffaf02adf6", "metadata": {}, "outputs": [], "source": [ "for iweight in weight_list:\n", " ck = torch.load(weight_dir + '/' + iweight + '.pt', map_location='cpu')\n", " ck_new = {}\n", " ck_new['num_edges'] = ck['num_edges']\n", " ck_new['noise_level'] = ck['noise_level']\n", " ck_new['model_state_dict'] = {}\n", " for ith, ijkey in enumerate(jkeys):\n", " itkey = tkeys[ith]\n", " if 'edge_embedding' in ijkey:\n", " ck_new['model_state_dict'][ijkey] = {'w': np.array(ck['model_state_dict'][itkey]).T}\n", " elif 'embed_token' in ijkey:\n", " ck_new['model_state_dict'][ijkey] = {'W_s': np.array(ck['model_state_dict'][itkey])}\n", " elif 'norm' in ijkey:\n", " ck_new['model_state_dict'][ijkey] = {'scale': np.array(ck['model_state_dict'][itkey + '.weight']),\n", " 'offset': np.array(ck['model_state_dict'][itkey + '.bias'])}\n", " else:\n", " ck_new['model_state_dict'][ijkey] = {'w': np.array(ck['model_state_dict'][itkey + '.weight']).T,\n", " 'b': np.array(ck['model_state_dict'][itkey + '.bias']).T}\n", " \n", " joblib.dump(ck_new, dest_dir + '/' + iweight + '.pkl')" ] }, { "cell_type": "code", "execution_count": null, "id": "d72eca08-24b8-4e8c-942d-93ebc4e35ee3", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "a6de4720-0c61-474d-9503-498c694c35f1", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "c84397b9-2857-43be-90cf-2be3a6525543", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "86ff0de3-2f1f-4319-a565-fa9a5eb97fdc", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.8.13 ('torch1.8')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.13" }, "vscode": { "interpreter": { "hash": "3ae0ca605930d43634b7fd9a0f47e12f386d3436786e739d9a5b581639944ad1" } } }, "nbformat": 4, "nbformat_minor": 5 }