Text Generation
Transformers
PyTorch
Safetensors
gpt2
code-generation
gpt2-large
text-generation-inference
Instructions to use DeathReaper0965/gpt2-large-code-generator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DeathReaper0965/gpt2-large-code-generator with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="DeathReaper0965/gpt2-large-code-generator")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("DeathReaper0965/gpt2-large-code-generator") model = AutoModelForCausalLM.from_pretrained("DeathReaper0965/gpt2-large-code-generator", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use DeathReaper0965/gpt2-large-code-generator with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "DeathReaper0965/gpt2-large-code-generator" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DeathReaper0965/gpt2-large-code-generator", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/DeathReaper0965/gpt2-large-code-generator
- SGLang
How to use DeathReaper0965/gpt2-large-code-generator with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "DeathReaper0965/gpt2-large-code-generator" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DeathReaper0965/gpt2-large-code-generator", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "DeathReaper0965/gpt2-large-code-generator" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DeathReaper0965/gpt2-large-code-generator", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use DeathReaper0965/gpt2-large-code-generator with Docker Model Runner:
docker model run hf.co/DeathReaper0965/gpt2-large-code-generator
Commit ·
1c256f5
1
Parent(s): 0b223ab
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
datasets:
|
| 4 |
+
- codeparrot/codeparrot-clean
|
| 5 |
+
tags:
|
| 6 |
+
- text-generation
|
| 7 |
+
- code-generation
|
| 8 |
+
- gpt2-large
|
| 9 |
+
widget:
|
| 10 |
+
- text: >-
|
| 11 |
+
def hello_world():
|
| 12 |
+
example_title: Code Generation Example 1
|
| 13 |
+
- text: >-
|
| 14 |
+
|
| 15 |
+
example_title: Code Generation Example 2
|
| 16 |
+
pipeline_tag: text-generation
|
| 17 |
+
inference:
|
| 18 |
+
parameters:
|
| 19 |
+
max_new_tokens: 30
|
| 20 |
+
temperature: 0.5
|
| 21 |
+
num_return_sequences: 1
|
| 22 |
+
do_sample: true
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# Code Generation using GPT2-Large
|
| 26 |
+
This is a GPT2-large model that's further fine-tuned on the Codeparrot clean dataset with a custom metric focused on code generation. <br>
|
| 27 |
+
I've further trained the tokenizer initialized from the GPT2-large on the same dataset to better align the tokenization for generating code.
|
| 28 |
+
|
| 29 |
+
## Model description
|
| 30 |
+
This Model has the same architecture and Parameters as the GPT2-large model. Please refer to this [link](https://d4mucfpksywv.cloudfront.net/better-language-models/language-models.pdf) to know more about the model details.
|
| 31 |
+
|
| 32 |
+
## Intended Use & Limitations
|
| 33 |
+
This model is intended to generate code for the required function based on a small description of the output required.<br>
|
| 34 |
+
|
| 35 |
+
**Note:** The model is primarily trained with an objective of code generation.
|
| 36 |
+
|
| 37 |
+
## Usage
|
| 38 |
+
|
| 39 |
+
You can use this model directly to get the summaries:
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
import torch
|
| 43 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 44 |
+
|
| 45 |
+
# Load Code Generator LLM and tokenizer from checkpoint
|
| 46 |
+
tokenizer = AutoTokenizer.from_pretrained("DeathReaper0965/gpt2_large_code_generator/", )
|
| 47 |
+
model = AutoModelForCausalLM.from_pretrained("DeathReaper0965/gpt2_large_code_generator/")
|
| 48 |
+
|
| 49 |
+
model = model.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 50 |
+
|
| 51 |
+
inputs = tokenizer("def hello_world():", return_tensors="pt").to("cuda")
|
| 52 |
+
outputs = model.generate(**inputs,
|
| 53 |
+
max_new_tokens= 30,
|
| 54 |
+
temperature= 0.5,
|
| 55 |
+
num_return_sequences= 1)
|
| 56 |
+
|
| 57 |
+
print(tokenizer.batch_decode(outputs)[0])
|
| 58 |
+
|
| 59 |
+
###########OUTPUT###########
|
| 60 |
+
def hello_world():
|
| 61 |
+
return "Hello World!"
|
| 62 |
+
|
| 63 |
+
@app.route("/hello_world")
|
| 64 |
+
def hello_world():
|
| 65 |
+
return "Hello World!"
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
> Designed and Developed with <span style="color: #e25555;">♥</span> by [Praneet](https://deathreaper0965.github.io/) | [LinkedIn](http://linkedin.com/in/deathreaper0965) | [GitHub](https://github.com/DeathReaper0965/)
|