myn11 commited on
Commit
5da3ef5
·
1 Parent(s): e2c7fac

gpt-2 ipynb upload

Browse files
Files changed (2) hide show
  1. Gradio_App_GPT_2_HDL.ipynb +124 -0
  2. LLM_for_HDL.ipynb +0 -0
Gradio_App_GPT_2_HDL.ipynb ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": null,
22
+ "metadata": {
23
+ "id": "nSYihpXyWYuv"
24
+ },
25
+ "outputs": [],
26
+ "source": [
27
+ "import pandas as pd\n",
28
+ "import torch\n",
29
+ "!pip install transformers"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "source": [
35
+ "!pip install -q gradio\n",
36
+ "import gradio as gr\n",
37
+ "from transformers import AutoModelForCausalLM, TrainingArguments, Trainer, pipeline, AutoTokenizer\n",
38
+ "model = AutoModelForCausalLM.from_pretrained('myn11/gpt2_hdl').to('cuda')\n",
39
+ "tokenizer = AutoTokenizer.from_pretrained('myn11/gpt2_hdl')"
40
+ ],
41
+ "metadata": {
42
+ "id": "--rUMbt6Wii1"
43
+ },
44
+ "execution_count": 4,
45
+ "outputs": []
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "source": [
50
+ "examples = [\n",
51
+ " ['summarise the code library IEEE;use IEEE.std_logic_1164.all;entity Top is port (dips_i : in std_logic_vector(3 downto 0);pbs_i : in std_logic;leds_o : out std_logic_vector(3 downto 0));end entity Top;architecture RTL of Top is begin leds_o <= dips_i when pbs_i=\"0\" else (others => \"1\"); end architecture RTL;'],\n",
52
+ " ['Explain the code library ieee;use ieee.std_logic_1164.all;entity test is port(clk : in std_logic;d : in std_logic ;q :out std_logic );end test;architecture rtl of test is begin process (clk) begin if rising_edge(clk) then q <= d; end if; end; end rtl;'],\n",
53
+ " ['Write a VHDL code for a read-only memory (ROM) module that takes an external data initialization file, and is parameterized by the data width, address width, and file name. The module should have an address input and a data output. It should read data from the file and provide the corresponding data output based on the given address.']\n",
54
+ "]\n",
55
+ "\n",
56
+ "title = \"GPT2 fine tuned for HDL\"\n",
57
+ "\n",
58
+ "def process_input(text):\n",
59
+ " input = tokenizer(text, truncation=True, return_tensors='pt').input_ids.to('cuda')\n",
60
+ " output = model.generate(input, max_length=1000, do_sample=True, top_k=50, top_p=0.92)\n",
61
+ " return tokenizer.batch_decode(output, skip_special_tokens=True)\n",
62
+ "\n",
63
+ "model_gui = gr.Interface(\n",
64
+ " process_input,\n",
65
+ " gr.Textbox(lines=3,label=\"Input\"),\n",
66
+ " gr.Textbox(lines=3, label=\"GPT2_HDL\"),\n",
67
+ " title=title,\n",
68
+ " examples=examples\n",
69
+ ")\n",
70
+ "model_gui.launch(share=True)"
71
+ ],
72
+ "metadata": {
73
+ "colab": {
74
+ "base_uri": "https://localhost:8080/",
75
+ "height": 611
76
+ },
77
+ "id": "adXT9D8jWiY3",
78
+ "outputId": "dad5cadf-1a6e-427f-d14f-d49151846bf0"
79
+ },
80
+ "execution_count": 5,
81
+ "outputs": [
82
+ {
83
+ "output_type": "stream",
84
+ "name": "stdout",
85
+ "text": [
86
+ "Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
87
+ "Running on public URL: https://90957029bf8cd47c54.gradio.live\n",
88
+ "\n",
89
+ "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
90
+ ]
91
+ },
92
+ {
93
+ "output_type": "display_data",
94
+ "data": {
95
+ "text/plain": [
96
+ "<IPython.core.display.HTML object>"
97
+ ],
98
+ "text/html": [
99
+ "<div><iframe src=\"https://90957029bf8cd47c54.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
100
+ ]
101
+ },
102
+ "metadata": {}
103
+ },
104
+ {
105
+ "output_type": "execute_result",
106
+ "data": {
107
+ "text/plain": []
108
+ },
109
+ "metadata": {},
110
+ "execution_count": 5
111
+ }
112
+ ]
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "source": [],
117
+ "metadata": {
118
+ "id": "MAqjgbJCWiMH"
119
+ },
120
+ "execution_count": null,
121
+ "outputs": []
122
+ }
123
+ ]
124
+ }
LLM_for_HDL.ipynb ADDED
The diff for this file is too large to render. See raw diff