Skip to content

Commit

Permalink
update example nb
Browse files Browse the repository at this point in the history
  • Loading branch information
dnth committed Oct 10, 2024
1 parent c78d3d0 commit 6e872b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

51 changes: 45 additions & 6 deletions example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 6e872b7

Please sign in to comment.