Instructions to use migueldeguzmandev/Phi-1.5-RLLMv3-8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use migueldeguzmandev/Phi-1.5-RLLMv3-8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="migueldeguzmandev/Phi-1.5-RLLMv3-8", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("migueldeguzmandev/Phi-1.5-RLLMv3-8", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("migueldeguzmandev/Phi-1.5-RLLMv3-8", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use migueldeguzmandev/Phi-1.5-RLLMv3-8 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "migueldeguzmandev/Phi-1.5-RLLMv3-8" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "migueldeguzmandev/Phi-1.5-RLLMv3-8", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/migueldeguzmandev/Phi-1.5-RLLMv3-8
- SGLang
How to use migueldeguzmandev/Phi-1.5-RLLMv3-8 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 "migueldeguzmandev/Phi-1.5-RLLMv3-8" \ --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": "migueldeguzmandev/Phi-1.5-RLLMv3-8", "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 "migueldeguzmandev/Phi-1.5-RLLMv3-8" \ --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": "migueldeguzmandev/Phi-1.5-RLLMv3-8", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use migueldeguzmandev/Phi-1.5-RLLMv3-8 with Docker Model Runner:
docker model run hf.co/migueldeguzmandev/Phi-1.5-RLLMv3-8
| import os | |
| import sys | |
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, TextDataset, DataCollatorForLanguageModeling, Trainer, TrainingArguments | |
| class GPTAssistant: | |
| def __init__(self, model_name="/Users/migueldeguzman/Desktop/gpt2xl_algos/phi-1.5/v7/"): # Replace with your specific Qwen model | |
| try: | |
| # Load the tokenizer and model using the specified Qwen model name | |
| self.tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True) | |
| self.model = AutoModelForCausalLM.from_pretrained(model_name) | |
| except Exception as e: | |
| print(f"Error initializing the model or tokenizer: {e}") | |
| sys.exit(1) | |
| def fine_tune(self, answer_file_path, model_output_dir, epochs=1.0): | |
| # Load dataset for training | |
| try: | |
| train_dataset = TextDataset( | |
| tokenizer=self.tokenizer, | |
| file_path=answer_file_path, | |
| block_size=128 | |
| ) | |
| except Exception as e: | |
| print(f"Error loading training dataset: {e}") | |
| sys.exit(1) # Exit the script if dataset loading fails | |
| # Prepare data collator for language modeling | |
| data_collator = DataCollatorForLanguageModeling( | |
| tokenizer=self.tokenizer, | |
| mlm=False | |
| ) | |
| total_steps = len(train_dataset) * epochs | |
| warmup_steps = 0.1 * total_steps | |
| # Set training arguments | |
| training_args = TrainingArguments( | |
| output_dir=model_output_dir, | |
| overwrite_output_dir=True, | |
| num_train_epochs=epochs, | |
| per_device_train_batch_size=4, | |
| save_steps=10_000, | |
| save_total_limit=2, | |
| weight_decay=0.005, | |
| gradient_accumulation_steps=8, | |
| learning_rate=15e-6, | |
| lr_scheduler_type='cosine', | |
| warmup_steps=warmup_steps | |
| ) | |
| # Initialize Trainer | |
| trainer = Trainer( | |
| model=self.model, | |
| args=training_args, | |
| data_collator=data_collator, | |
| train_dataset=train_dataset | |
| ) | |
| # Train and save the model | |
| trainer.train() | |
| self.model.save_pretrained(model_output_dir) | |
| self.tokenizer.save_pretrained(model_output_dir) | |
| def main(): | |
| # Specify the file path for training data and output directory | |
| text_file_path = "/Users/migueldeguzman/Desktop/gpt2xl_algos/phi-1.5/v8/q&a_test_v1-3.text" # Replace with your training data file path | |
| model_output_dir = "/Users/migueldeguzman/Desktop/gpt2xl_algos/phi-1.5/v8/" # Replace with your desired output directory | |
| # Initialize GPTAssistant and fine-tune the model | |
| assistant = GPTAssistant() | |
| assistant.fine_tune(text_file_path, model_output_dir) | |
| if __name__ == "__main__": | |
| main() | |