Agon H commited on
Commit
5d1ca35
·
1 Parent(s): 15e1cf4

Upload run in GPU.ipynb

Browse files
Files changed (1) hide show
  1. run in GPU.ipynb +77 -0
run in GPU.ipynb ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": [],
7
+ "gpuType": "T4"
8
+ },
9
+ "kernelspec": {
10
+ "name": "python3",
11
+ "display_name": "Python 3"
12
+ },
13
+ "language_info": {
14
+ "name": "python"
15
+ },
16
+ "accelerator": "GPU"
17
+ },
18
+ "cells": [
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": 1,
22
+ "metadata": {
23
+ "id": "CIUy2FYzfFEJ"
24
+ },
25
+ "outputs": [],
26
+ "source": [
27
+ "%%capture\n",
28
+ "!pip install transformers\n",
29
+ "!pip install einops\n",
30
+ "!pip install accelerate\n",
31
+ "\n",
32
+ "import torch\n",
33
+ "from transformers import AutoModelForCausalLM, AutoTokenizer\n",
34
+ "\n",
35
+ "model = AutoModelForCausalLM.from_pretrained(\"agonh/phi-base_model\", trust_remote_code=True, device_map=\"cuda:0\")\n",
36
+ "tokenizer = AutoTokenizer.from_pretrained(\"agonh/phi-base_model\", trust_remote_code=True, device_map=\"cuda:0\")"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "source": [
42
+ "prompt = \"tell me about the moon ?\"\n",
43
+ "inputs = tokenizer(prompt, return_tensors=\"pt\", return_attention_mask=False)\n",
44
+ "\n",
45
+ "inputs.to(\"cuda:0\")\n",
46
+ "outputs = model.generate(**inputs, max_length=100)\n",
47
+ "text = tokenizer.batch_decode(outputs)[0]\n",
48
+ "print(text)"
49
+ ],
50
+ "metadata": {
51
+ "colab": {
52
+ "base_uri": "https://localhost:8080/"
53
+ },
54
+ "id": "87vmiui3jGK7",
55
+ "outputId": "46fb0454-8b29-4a76-cb1c-1d1c7c7c28c2"
56
+ },
57
+ "execution_count": 2,
58
+ "outputs": [
59
+ {
60
+ "output_type": "stream",
61
+ "name": "stdout",
62
+ "text": [
63
+ "tell me about the moon?\n",
64
+ "\n",
65
+ "Teacher: The moon is a natural satellite of the Earth. It is the fifth largest moon in the solar system and is about 238,900 miles away from the Earth.\n",
66
+ "\n",
67
+ "Student: Wow, that's a really big distance!\n",
68
+ "\n",
69
+ "Teacher: Yes, it is. The moon has a lot of interesting features, like craters and mountains. It also affects the tides on Earth.\n",
70
+ "\n",
71
+ "Student: How does the moon affect the tides\n"
72
+ ]
73
+ }
74
+ ]
75
+ }
76
+ ]
77
+ }