Skip to content

Instantly share code, notes, and snippets.

@nateraw
Created September 3, 2021 20:40
Show Gist options
  • Save nateraw/7a87ba17114e29727fbeb557551c1b98 to your computer and use it in GitHub Desktop.
Save nateraw/7a87ba17114e29727fbeb557551c1b98 to your computer and use it in GitHub Desktop.
pytorch-push-to-hub.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "pytorch-push-to-hub.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyOMOFThFPzk/yZ/Fi7DroBq",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/nateraw/7a87ba17114e29727fbeb557551c1b98/pytorch-push-to-hub.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "1ph38Q7rXFre"
},
"source": [
"%%capture\n",
"! pip install huggingface_hub\n",
"\n",
"# Install git-lfs, as it's required to push to hub\n",
"! apt install git-lfs\n",
"\n",
"# 🚨 - Replace with your git info!\n",
"# ...or you can remove and manually pass git_email and git_username to push_to_hub\n",
"! git config --global user.name \"nateraw\"\n",
"! git config --global user.email \"naterawdata@gmail.com\"\n",
"\n",
"# Enable credential helper used by huggingface-cli\n",
"! git config --global credential.helper store"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "SJm1jsgjXJjX"
},
"source": [
"# Log in with your Hugging Face account\n",
"! huggingface-cli login"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "F7FBv8U2XFB5"
},
"source": [
"from huggingface_hub import PyTorchModelHubMixin\n",
"import torch.nn as nn\n",
"import torch.nn.functional as F\n",
"\n",
"class Model(nn.Module, PyTorchModelHubMixin):\n",
" def __init__(self):\n",
" super(Model, self).__init__()\n",
" self.conv1 = nn.Conv2d(1, 20, 5)\n",
" self.conv2 = nn.Conv2d(20, 20, 5)\n",
"\n",
" def forward(self, x):\n",
" x = F.relu(self.conv1(x))\n",
" return F.relu(self.conv2(x))\n",
"\n",
"model = Model()\n",
"model.push_to_hub(\"cnn-dummy\")"
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment