From 6e872b73abffa7cc70224cea42d52df6eb88aac9 Mon Sep 17 00:00:00 2001 From: dnth Date: Thu, 10 Oct 2024 13:59:42 +0800 Subject: [PATCH] update example nb --- README.md | 6 +++--- example.ipynb | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2883268..7561c22 100644 --- a/README.md +++ b/README.md @@ -115,13 +115,13 @@ See [example.ipynb](example.ipynb) for more examples. ## Adding New Models -Step 1: Create a new model class that implements the `BaseModel` interface. ++ Step 1: Create a new model class that implements the `BaseModel` interface. -Step 2: Implement the required abstract methods: ++ Step 2: Implement the required abstract methods: - `load_model` - `preprocess` - `predict` - `postprocess` -Step 3: Update `register_models` in `model_factory.py` to import the new model class and register it. ++ Step 3: Update `register_models` in `model_factory.py` to import the new model class and register it. diff --git a/example.ipynb b/example.ipynb index 34fcfff..44beff1 100644 --- a/example.ipynb +++ b/example.ipynb @@ -67,7 +67,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "Loading checkpoint shards: 100%|██████████| 2/2 [00:00<00:00, 4.90it/s]\n", + "Loading checkpoint shards: 100%|██████████| 2/2 [00:00<00:00, 4.97it/s]\n", "Expanding inputs for image tokens in BLIP-2 should be done in processing. Please follow instruction here (https://gist.github.com/zucchini-nlp/e9f20b054fa322f84ac9311d9ab67042) to update your BLIP-2 model. Using processors without these attributes in the config is deprecated and will throw an error in v4.47.\n", "Expanding inputs for image tokens in BLIP-2 should be done in processing. Please follow instruction here (https://gist.github.com/zucchini-nlp/e9f20b054fa322f84ac9311d9ab67042) to update your BLIP-2 model. Using processors without these attributes in the config is deprecated and will throw an error in v4.47.\n" ] @@ -158,7 +158,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "Loading checkpoint shards: 100%|██████████| 8/8 [00:02<00:00, 3.24it/s]\n", + "Loading checkpoint shards: 100%|██████████| 8/8 [00:02<00:00, 3.20it/s]\n", "/home/dnth/Desktop/InferX/InferX/transformers/blip2.py:57: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.\n", " finetuned_weights_state_dict = torch.load(\n", "Both `max_new_tokens` (=200) and `max_length`(=51) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)\n" @@ -201,9 +201,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "Loading checkpoint shards: 100%|██████████| 2/2 [00:01<00:00, 1.10it/s]\n", + "Both `max_new_tokens` (=20) and `max_length`(=51) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)\n" + ] + }, + { + "data": { + "text/plain": [ + "'a black and white cat sitting on a table'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import torch\n", "import requests\n", @@ -224,9 +243,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/tmp/ipykernel_42052/3377070460.py:2: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.\n", + " finetuned_weights_state_dict = torch.load(hf_hub_download(repo_id=\"sashakunitsyn/vlrm-blip2-opt-2.7b\", filename=\"vlrm-blip2-opt-2.7b.pt\"))\n", + "Both `max_new_tokens` (=20) and `max_length`(=51) seem to have been set. `max_new_tokens` will take precedence. Please refer to the documentation for more information. (https://huggingface.co/docs/transformers/main/en/main_classes/text_generation)\n" + ] + }, + { + "data": { + "text/plain": [ + "'a black and white cat with white eyes sitting on a table, in front of himself, in front'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from huggingface_hub import hf_hub_download\n", "finetuned_weights_state_dict = torch.load(hf_hub_download(repo_id=\"sashakunitsyn/vlrm-blip2-opt-2.7b\", filename=\"vlrm-blip2-opt-2.7b.pt\"))\n",