{
  "id": 245035,
  "title": "Save and load pretrained huggingface models",
  "url": "/competitions/coleridgeinitiative-show-us-the-data/discussion/245035",
  "author_name": "",
  "post_date": "2021-06-09T11:14:59.444747800Z",
  "votes": 1,
  "comment_count": 1,
  "views": 0,
  "content": "<p>Hi guys, I've a question regarding saving pretrained huggingface models to use them later in a notebook without internet.</p>\n<p>The point is that I have saved 2 different models as a private dataset, 1 loads correctly but the other gives an error.</p>\n<ol>\n<li>The correct one (microsoft/deberta-base):<br>\nI download it in a kaggle notebook using the following code:</li>\n</ol>\n<p>`from transformers import DebertaTokenizer, DebertaModel</p>\n<p>tokenizer = DebertaTokenizer.from_pretrained(\"microsoft/deberta-base\")</p>\n<p>model_t = DebertaModel.from_pretrained(\"microsoft/deberta-base\")</p>\n<p>tokenizer.save_pretrained(\"v2/deberta-base-tok\")<br>\nmodel_t.save_pretrained(\"v2/deberta-base-model\")`</p>\n<p>And the outout is this one:<br>\nv2:<br>\n    deberta-base-model:<br>\n        config.json<br>\n        pytorch_model.bin</p>\n<pre><code>deberta-base-tok:\n    merges.txt\n    special_tokens_map.json\n    tokenizer_config.json\n    vocab.json\n\nThen I save the model as private dataset and load it again in another kaggle nb with the following code:\n</code></pre>\n<p><code>tokenizer_d = DebertaTokenizer.from_pretrained(\"../input/deberta2/v2/deberta-base-tok\")\nmodel_d = DebertaModel.from_pretrained(\"../input/deberta2/v2/deberta-base-model\")</code><br>\n   And it loads and work correctly</p>\n<ol>\n<li>The \"wrong\" one (paraphrase-mpnet-base-v2):<br>\n I download it in a kaggle notebook using the following code:</li>\n</ol>\n<p>`from transformers import AutoTokenizer, AutoModel</p>\n<p>tokenizer_pm = AutoTokenizer.from_pretrained(\"sentence-transformers/paraphrase-mpnet-base-v2\")<br>\nmodel_pm = AutoModel.from_pretrained(\"sentence-transformers/paraphrase-mpnet-base-v2\")</p>\n<p>tokenizer_pm.save_pretrained(\"paraphrase-mpnet-tok\")<br>\nmodel_pm.save_pretrained(\"paraphrase-mpnet-model\")`</p>\n<p>And the output is this one:</p>\n<pre><code>paraphrase-mpnet-model:\n    config.json\n    pytorch_model.bin\n\nparaphrase-mpnet-tok:\n    special_tokens_map.json\n    tokenizer_config.json\n    vocab.txt\n</code></pre>\n<p>As you can see the tokenizer schema is different.</p>\n<pre><code>Then I save the model as private dataset and when I try to load it in a new kaggle notebook with the following code:\n</code></pre>\n<p><code>tokenizer_pm = AutoTokenizer.from_pretrained(\"../input/pmpnet/paraphrase-mpnet-tok\")\nmodel_pm = AutoModel.from_pretrained(\"../input/pmpnet/paraphrase-mpnet-model\")</code></p>\n<p>I get this error:<br>\n`OSError: Can't load config for '../input/pmpnet/paraphrase-mpnet-tok'. Make sure that:</p>\n<ul>\n<li><p>'../input/pmpnet/paraphrase-mpnet-tok' is a correct model identifier listed on 'https://huggingface.co/models'</p></li>\n<li><p>or '../input/pmpnet/paraphrase-mpnet-tok' is the correct path to a directory containing a config.json file`</p></li>\n</ul>\n<p>Any idea of why the second model is saved with a different schema? How could be solved?</p>\n<p>Thanks in advance</p>",
  "messages": [
    {
      "id": "1342345",
      "postDate": "06/09/2021 11:14:59",
      "content": "<p>Hi guys, I've a question regarding saving pretrained huggingface models to use them later in a notebook without internet.</p>\n<p>The point is that I have saved 2 different models as a private dataset, 1 loads correctly but the other gives an error.</p>\n<ol>\n<li>The correct one (microsoft/deberta-base):<br>\nI download it in a kaggle notebook using the following code:</li>\n</ol>\n<p>`from transformers import DebertaTokenizer, DebertaModel</p>\n<p>tokenizer = DebertaTokenizer.from_pretrained(\"microsoft/deberta-base\")</p>\n<p>model_t = DebertaModel.from_pretrained(\"microsoft/deberta-base\")</p>\n<p>tokenizer.save_pretrained(\"v2/deberta-base-tok\")<br>\nmodel_t.save_pretrained(\"v2/deberta-base-model\")`</p>\n<p>And the outout is this one:<br>\nv2:<br>\n    deberta-base-model:<br>\n        config.json<br>\n        pytorch_model.bin</p>\n<pre><code>deberta-base-tok:\n    merges.txt\n    special_tokens_map.json\n    tokenizer_config.json\n    vocab.json\n\nThen I save the model as private dataset and load it again in another kaggle nb with the following code:\n</code></pre>\n<p><code>tokenizer_d = DebertaTokenizer.from_pretrained(\"../input/deberta2/v2/deberta-base-tok\")\nmodel_d = DebertaModel.from_pretrained(\"../input/deberta2/v2/deberta-base-model\")</code><br>\n   And it loads and work correctly</p>\n<ol>\n<li>The \"wrong\" one (paraphrase-mpnet-base-v2):<br>\n I download it in a kaggle notebook using the following code:</li>\n</ol>\n<p>`from transformers import AutoTokenizer, AutoModel</p>\n<p>tokenizer_pm = AutoTokenizer.from_pretrained(\"sentence-transformers/paraphrase-mpnet-base-v2\")<br>\nmodel_pm = AutoModel.from_pretrained(\"sentence-transformers/paraphrase-mpnet-base-v2\")</p>\n<p>tokenizer_pm.save_pretrained(\"paraphrase-mpnet-tok\")<br>\nmodel_pm.save_pretrained(\"paraphrase-mpnet-model\")`</p>\n<p>And the output is this one:</p>\n<pre><code>paraphrase-mpnet-model:\n    config.json\n    pytorch_model.bin\n\nparaphrase-mpnet-tok:\n    special_tokens_map.json\n    tokenizer_config.json\n    vocab.txt\n</code></pre>\n<p>As you can see the tokenizer schema is different.</p>\n<pre><code>Then I save the model as private dataset and when I try to load it in a new kaggle notebook with the following code:\n</code></pre>\n<p><code>tokenizer_pm = AutoTokenizer.from_pretrained(\"../input/pmpnet/paraphrase-mpnet-tok\")\nmodel_pm = AutoModel.from_pretrained(\"../input/pmpnet/paraphrase-mpnet-model\")</code></p>\n<p>I get this error:<br>\n`OSError: Can't load config for '../input/pmpnet/paraphrase-mpnet-tok'. Make sure that:</p>\n<ul>\n<li><p>'../input/pmpnet/paraphrase-mpnet-tok' is a correct model identifier listed on 'https://huggingface.co/models'</p></li>\n<li><p>or '../input/pmpnet/paraphrase-mpnet-tok' is the correct path to a directory containing a config.json file`</p></li>\n</ul>\n<p>Any idea of why the second model is saved with a different schema? How could be solved?</p>\n<p>Thanks in advance</p>",
      "rawMarkdown": "Hi guys, I've a question regarding saving pretrained huggingface models to use them later in a notebook without internet.\n\nThe point is that I have saved 2 different models as a private dataset, 1 loads correctly but the other gives an error.\n\n1. The correct one (microsoft/deberta-base):\n    I download it in a kaggle notebook using the following code:\n\n`from transformers import DebertaTokenizer, DebertaModel\n  \ntokenizer = DebertaTokenizer.from_pretrained(\"microsoft/deberta-base\")\n\nmodel_t = DebertaModel.from_pretrained(\"microsoft/deberta-base\")\n\ntokenizer.save_pretrained(\"v2/deberta-base-tok\")\nmodel_t.save_pretrained(\"v2/deberta-base-model\")`\n\nAnd the outout is this one:\nv2:\n    deberta-base-model:\n        config.json\n        pytorch_model.bin\n\n    deberta-base-tok:\n        merges.txt\n        special_tokens_map.json\n        tokenizer_config.json\n        vocab.json\n\n    Then I save the model as private dataset and load it again in another kaggle nb with the following code:\n`tokenizer_d = DebertaTokenizer.from_pretrained(\"../input/deberta2/v2/deberta-base-tok\")\nmodel_d = DebertaModel.from_pretrained(\"../input/deberta2/v2/deberta-base-model\")`\n   And it loads and work correctly\n\n2. The \"wrong\" one (paraphrase-mpnet-base-v2):\n     I download it in a kaggle notebook using the following code:\n\n`from transformers import AutoTokenizer, AutoModel\n  \ntokenizer_pm = AutoTokenizer.from_pretrained(\"sentence-transformers/paraphrase-mpnet-base-v2\")\nmodel_pm = AutoModel.from_pretrained(\"sentence-transformers/paraphrase-mpnet-base-v2\")\n\ntokenizer_pm.save_pretrained(\"paraphrase-mpnet-tok\")\nmodel_pm.save_pretrained(\"paraphrase-mpnet-model\")`\n\nAnd the output is this one:\n\n    paraphrase-mpnet-model:\n        config.json\n        pytorch_model.bin\n\n    paraphrase-mpnet-tok:\n        special_tokens_map.json\n        tokenizer_config.json\n        vocab.txt\n\nAs you can see the tokenizer schema is different.\n\n    Then I save the model as private dataset and when I try to load it in a new kaggle notebook with the following code:\n`tokenizer_pm = AutoTokenizer.from_pretrained(\"../input/pmpnet/paraphrase-mpnet-tok\")\nmodel_pm = AutoModel.from_pretrained(\"../input/pmpnet/paraphrase-mpnet-model\")`\n\n   I get this error:\n`OSError: Can't load config for '../input/pmpnet/paraphrase-mpnet-tok'. Make sure that:\n\n- '../input/pmpnet/paraphrase-mpnet-tok' is a correct model identifier listed on 'https://huggingface.co/models'\n\n- or '../input/pmpnet/paraphrase-mpnet-tok' is the correct path to a directory containing a config.json file`\n\n\nAny idea of why the second model is saved with a different schema? How could be solved?\n\nThanks in advance",
      "votes": null
    },
    {
      "id": "1342537",
      "postDate": "06/09/2021 14:36:14",
      "content": "<p>I was able to solve it by using the main tokenizer and model --&gt; MPNetTokenizer, ModelTokenizer, in both save and load</p>",
      "rawMarkdown": "I was able to solve it by using the main tokenizer and model --> MPNetTokenizer, ModelTokenizer, in both save and load",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1342537,
      "author_name": "diegoflorezestrada",
      "author_url": "",
      "post_date": "06/09/2021 14:36:14",
      "content": "<p>I was able to solve it by using the main tokenizer and model --&gt; MPNetTokenizer, ModelTokenizer, in both save and load</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1342345": "Hi guys, I've a question regarding saving pretrained huggingface models to use them later in a notebook without internet.\n\nThe point is that I have saved 2 different models as a private dataset, 1 loads correctly but the other gives an error.\n\n1. The correct one (microsoft/deberta-base):\n    I download it in a kaggle notebook using the following code:\n\n`from transformers import DebertaTokenizer, DebertaModel\n  \ntokenizer = DebertaTokenizer.from_pretrained(\"microsoft/deberta-base\")\n\nmodel_t = DebertaModel.from_pretrained(\"microsoft/deberta-base\")\n\ntokenizer.save_pretrained(\"v2/deberta-base-tok\")\nmodel_t.save_pretrained(\"v2/deberta-base-model\")`\n\nAnd the outout is this one:\nv2:\n    deberta-base-model:\n        config.json\n        pytorch_model.bin\n\n    deberta-base-tok:\n        merges.txt\n        special_tokens_map.json\n        tokenizer_config.json\n        vocab.json\n\n    Then I save the model as private dataset and load it again in another kaggle nb with the following code:\n`tokenizer_d = DebertaTokenizer.from_pretrained(\"../input/deberta2/v2/deberta-base-tok\")\nmodel_d = DebertaModel.from_pretrained(\"../input/deberta2/v2/deberta-base-model\")`\n   And it loads and work correctly\n\n2. The \"wrong\" one (paraphrase-mpnet-base-v2):\n     I download it in a kaggle notebook using the following code:\n\n`from transformers import AutoTokenizer, AutoModel\n  \ntokenizer_pm = AutoTokenizer.from_pretrained(\"sentence-transformers/paraphrase-mpnet-base-v2\")\nmodel_pm = AutoModel.from_pretrained(\"sentence-transformers/paraphrase-mpnet-base-v2\")\n\ntokenizer_pm.save_pretrained(\"paraphrase-mpnet-tok\")\nmodel_pm.save_pretrained(\"paraphrase-mpnet-model\")`\n\nAnd the output is this one:\n\n    paraphrase-mpnet-model:\n        config.json\n        pytorch_model.bin\n\n    paraphrase-mpnet-tok:\n        special_tokens_map.json\n        tokenizer_config.json\n        vocab.txt\n\nAs you can see the tokenizer schema is different.\n\n    Then I save the model as private dataset and when I try to load it in a new kaggle notebook with the following code:\n`tokenizer_pm = AutoTokenizer.from_pretrained(\"../input/pmpnet/paraphrase-mpnet-tok\")\nmodel_pm = AutoModel.from_pretrained(\"../input/pmpnet/paraphrase-mpnet-model\")`\n\n   I get this error:\n`OSError: Can't load config for '../input/pmpnet/paraphrase-mpnet-tok'. Make sure that:\n\n- '../input/pmpnet/paraphrase-mpnet-tok' is a correct model identifier listed on 'https://huggingface.co/models'\n\n- or '../input/pmpnet/paraphrase-mpnet-tok' is the correct path to a directory containing a config.json file`\n\n\nAny idea of why the second model is saved with a different schema? How could be solved?\n\nThanks in advance",
    "1342537": "I was able to solve it by using the main tokenizer and model --> MPNetTokenizer, ModelTokenizer, in both save and load"
  },
  "source": "meta"
}