Upload tryingothers.ipynb
Browse files- tryingothers.ipynb +118 -0
tryingothers.ipynb
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stderr",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"c:\\Users\\harsh\\anaconda3\\envs\\transformmers\\lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
13 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"import torch\n",
|
19 |
+
"from PIL import Image\n",
|
20 |
+
"from transformers import AutoModel, AutoTokenizer"
|
21 |
+
]
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"cell_type": "code",
|
25 |
+
"execution_count": null,
|
26 |
+
"metadata": {},
|
27 |
+
"outputs": [],
|
28 |
+
"source": [
|
29 |
+
"pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121"
|
30 |
+
]
|
31 |
+
},
|
32 |
+
{
|
33 |
+
"cell_type": "code",
|
34 |
+
"execution_count": 3,
|
35 |
+
"metadata": {},
|
36 |
+
"outputs": [
|
37 |
+
{
|
38 |
+
"name": "stderr",
|
39 |
+
"output_type": "stream",
|
40 |
+
"text": [
|
41 |
+
"Loading checkpoint shards: 100%|ββββββββββ| 2/2 [00:11<00:00, 5.61s/it]\n"
|
42 |
+
]
|
43 |
+
}
|
44 |
+
],
|
45 |
+
"source": [
|
46 |
+
"model = AutoModel.from_pretrained('MiniCPM', trust_remote_code=True, torch_dtype=torch.bfloat16)\n",
|
47 |
+
"# For Nvidia GPUs support BF16 (like A100, H100, RTX3090)\n",
|
48 |
+
"model = model.to(device='cuda', dtype=torch.bfloat16)"
|
49 |
+
]
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"cell_type": "code",
|
53 |
+
"execution_count": 4,
|
54 |
+
"metadata": {},
|
55 |
+
"outputs": [],
|
56 |
+
"source": [
|
57 |
+
"tokenizer = AutoTokenizer.from_pretrained('MiniCPM-Tokenizer', trust_remote_code=True)\n"
|
58 |
+
]
|
59 |
+
},
|
60 |
+
{
|
61 |
+
"cell_type": "code",
|
62 |
+
"execution_count": 5,
|
63 |
+
"metadata": {},
|
64 |
+
"outputs": [
|
65 |
+
{
|
66 |
+
"name": "stdout",
|
67 |
+
"output_type": "stream",
|
68 |
+
"text": [
|
69 |
+
"The image depicts a breathtaking view of a rocky coastline. The rocky cliff, with its steep and rugged terrain, dominates the left side of the frame. The water, which is a shade of blue, is calm and stretches out to the right of the image. The coastline appears to be rocky and uneven, with a variety of shapes and sizes of rocks and boulders. The image also captures a glimpse of the sky, which is visible at the top of the frame.\n"
|
70 |
+
]
|
71 |
+
}
|
72 |
+
],
|
73 |
+
"source": [
|
74 |
+
"image = Image.open('demo2.jpg').convert('RGB')\n",
|
75 |
+
"question = 'What is in the image?'\n",
|
76 |
+
"msgs = [{'role': 'user', 'content': question}]\n",
|
77 |
+
"\n",
|
78 |
+
"res, context, _ = model.chat(\n",
|
79 |
+
" image=image,\n",
|
80 |
+
" msgs=msgs,\n",
|
81 |
+
" context=None,\n",
|
82 |
+
" tokenizer=tokenizer,\n",
|
83 |
+
" sampling=True,\n",
|
84 |
+
" temperature=0.7\n",
|
85 |
+
")\n",
|
86 |
+
"print(res)"
|
87 |
+
]
|
88 |
+
},
|
89 |
+
{
|
90 |
+
"cell_type": "code",
|
91 |
+
"execution_count": null,
|
92 |
+
"metadata": {},
|
93 |
+
"outputs": [],
|
94 |
+
"source": []
|
95 |
+
}
|
96 |
+
],
|
97 |
+
"metadata": {
|
98 |
+
"kernelspec": {
|
99 |
+
"display_name": "transformmers",
|
100 |
+
"language": "python",
|
101 |
+
"name": "python3"
|
102 |
+
},
|
103 |
+
"language_info": {
|
104 |
+
"codemirror_mode": {
|
105 |
+
"name": "ipython",
|
106 |
+
"version": 3
|
107 |
+
},
|
108 |
+
"file_extension": ".py",
|
109 |
+
"mimetype": "text/x-python",
|
110 |
+
"name": "python",
|
111 |
+
"nbconvert_exporter": "python",
|
112 |
+
"pygments_lexer": "ipython3",
|
113 |
+
"version": "3.9.19"
|
114 |
+
}
|
115 |
+
},
|
116 |
+
"nbformat": 4,
|
117 |
+
"nbformat_minor": 2
|
118 |
+
}
|