{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "dd05f32c-a90f-4122-b6d7-a5ec7b3b9ba0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "env: HF_ENDPOINT=https://hf-mirror.com\n" ] } ], "source": [ "%env HF_ENDPOINT=https://hf-mirror.com" ] }, { "cell_type": "code", "execution_count": 2, "id": "54f03217-da8d-4a05-9c85-9e0301a597e7", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "# 设置 HF_HOME 环境变量 设置下载路径\n", "os.environ['HF_HOME'] = '/data1/ckw'" ] }, { "cell_type": "code", "execution_count": null, "id": "94cab483-b247-4aa8-9557-d15e459244af", "metadata": {}, "outputs": [], "source": [ "# 这个时候,由于OpenELM还没有官方发布在transformer,所以需要改下源码(已经有了更好的办法,因此不需要改源码了)" ] }, { "cell_type": "code", "execution_count": null, "id": "e2f3081d-f795-4f86-b80e-e915ae56b426", "metadata": {}, "outputs": [], "source": [ "# /data1/ckw/micromamba/envs/kewei-ai/lib/python3.11/site-packages/transformers/models/auto/tokenization_auto.py:909" ] }, { "cell_type": "markdown", "id": "db03e7fd-d06f-4e78-842f-66c8e02043bd", "metadata": {}, "source": [ "#### 1.3 AutoModelForCausalLM代码\n", "\n", "```python\n", "class AutoModelForCausalLM:\n", " def __init__(self):\n", " raise EnvironmentError(\n", " \"AutoModelForCausalLM is designed to be instantiated \"\n", " \"using the `AutoModelForCausalLM.from_pretrained(pretrained_model_name_or_path)` or \"\n", " \"`AutoModelForCausalLM.from_config(config)` methods.\"\n", " )\n", "\n", "\t@classmethod\n", " @replace_list_option_in_docstrings(MODEL_FOR_CAUSAL_LM_MAPPING, use_model_types=False)\n", " def from_config(cls, config):\n", "\n", " if type(config) in MODEL_FOR_CAUSAL_LM_MAPPING.keys():\n", " return MODEL_FOR_CAUSAL_LM_MAPPING[type(config)](config)\n", " raise ValueError(\n", " \"Unrecognized configuration class {} for this kind of AutoModel: {}.\\n\"\n", " \"Model type should be one of {}.\".format(\n", " config.__class__, cls.__name__, \", \".join(c.__name__ for c in MODEL_FOR_CAUSAL_LM_MAPPING.keys())\n", " )\n", " )\n", "\n", "\n", "\t@classmethod\n", " @replace_list_option_in_docstrings(MODEL_FOR_CAUSAL_LM_MAPPING)\n", " @add_start_docstrings(\n", " \"Instantiate one of the model classes of the library---with a causal language modeling head---from a \"\n", " \"pretrained model.\",\n", " AUTO_MODEL_PRETRAINED_DOCSTRING,\n", " )\n", " def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):\n", " config = kwargs.pop(\"config\", None)\n", " if not isinstance(config, PretrainedConfig):\n", " config, kwargs = AutoConfig.from_pretrained(\n", " pretrained_model_name_or_path, return_unused_kwargs=True, **kwargs\n", " )\n", "\n", " if type(config) in MODEL_FOR_CAUSAL_LM_MAPPING.keys():\n", " return MODEL_FOR_CAUSAL_LM_MAPPING[type(config)].from_pretrained(\n", " pretrained_model_name_or_path, *model_args, config=config, **kwargs\n", " )\n", " raise ValueError(\n", " \"Unrecognized configuration class {} for this kind of AutoModel: {}.\\n\"\n", " \"Model type should be one of {}.\".format(\n", " config.__class__, cls.__name__, \", \".join(c.__name__ for c in MODEL_FOR_CAUSAL_LM_MAPPING.keys())\n", " )\n", " )\n", "```" ] }, { "cell_type": "code", "execution_count": 5, "id": "744c6db7-53f9-4911-adcb-4f0618693071", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7dd376f050c3496b904a5a545f499e07", "version_major": 2, "version_minor": 0 }, "text/plain": [ "tokenizer_config.json: 0%| | 0.00/265 [00:00