Instructions to use Autsadin/gpt2_instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Autsadin/gpt2_instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Autsadin/gpt2_instruct")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Autsadin/gpt2_instruct") model = AutoModelForCausalLM.from_pretrained("Autsadin/gpt2_instruct", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Autsadin/gpt2_instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Autsadin/gpt2_instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Autsadin/gpt2_instruct", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Autsadin/gpt2_instruct
- SGLang
How to use Autsadin/gpt2_instruct 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 "Autsadin/gpt2_instruct" \ --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": "Autsadin/gpt2_instruct", "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 "Autsadin/gpt2_instruct" \ --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": "Autsadin/gpt2_instruct", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Autsadin/gpt2_instruct with Docker Model Runner:
docker model run hf.co/Autsadin/gpt2_instruct
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Fine-Tuned GPT-2 Model for Instruction-Based Tasks
This model is a fine-tuned version of GPT-2, adapted for instruction-based tasks. It has been trained to provide helpful and coherent responses to a variety of prompts.
Model Description
This model is based on OpenAI's GPT-2 architecture and has been fine-tuned to respond to instructions in a format that mimics conversational exchanges. The fine-tuning process enhances its ability to follow specific instructions and generate appropriate responses, making it a valuable tool for interactive applications.
Example Usage
Below is an example of how to use the fine-tuned model in your application:
import torch
import random
import numpy as np
from transformers import GPT2LMHeadModel, GPT2Tokenizer
# Load the fine-tuned model and tokenizer
model = GPT2LMHeadModel.from_pretrained("Autsadin/gpt2_instruct")
tokenizer = GPT2Tokenizer.from_pretrained("Autsadin/gpt2_instruct")
# Define the template for instruction-based prompts
template = '''<s>[INST] <<SYS>>
You are a helpful assistant
<</SYS>>
{instruct}[/INST]'''
# Function to format prompts using the template
def format_entry(prompt):
return template.format(instruct=prompt)
# Define the input prompt
prompt = "What is a dog?"
# Tokenize the input prompt
inputs = tokenizer.encode(format_entry(prompt), return_tensors='pt')
# Generate a response
outputs = model.generate(
inputs,
max_length=256,
num_return_sequences=1,
top_k=50,
top_p=0.95,
temperature=0.8,
pad_token_id=tokenizer.eos_token_id,
do_sample=True,
early_stopping=True
)
# Decode and print the generated text
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_text)
Explanation:
#Training Data The model was fine-tuned using the Alpaca GPT-4 dataset available at the following GitHub repository. https://github.com/hy5468/TransLLM/tree/main/data/train Specifically, the alpaca_gpt4_data_en.zip dataset was utilized. This dataset includes a wide range of instruction-based prompts and responses, providing a robust foundation for the model's training.
#Training Procedure The fine-tuning process was carried out with the following hyperparameters: Learning Rate: 2e-5 Batch Size (Train): 4 Batch Size (Eval): 4 Number of Epochs: 1 Weight Decay: 0.01
#Training Environment The model was trained using PyTorch and the Hugging Face transformers library. The training was performed on a GPU-enabled environment to accelerate the fine-tuning process.The training script ensures reproducibility by setting a consistent random seed across different components.
- Downloads last month
- 7