Text Generation
PEFT
Safetensors
Transformers
English
llama
lora
dpo
smollm2
trl
conversational
text-generation-inference
Instructions to use Subject-Emu-5259/NeuralAI with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Subject-Emu-5259/NeuralAI with PEFT:
Base model is not found.
- Transformers
How to use Subject-Emu-5259/NeuralAI with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Subject-Emu-5259/NeuralAI", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Subject-Emu-5259/NeuralAI") model = AutoModelForCausalLM.from_pretrained("Subject-Emu-5259/NeuralAI", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Subject-Emu-5259/NeuralAI with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Subject-Emu-5259/NeuralAI" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Subject-Emu-5259/NeuralAI", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Subject-Emu-5259/NeuralAI
- SGLang
How to use Subject-Emu-5259/NeuralAI 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 "Subject-Emu-5259/NeuralAI" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Subject-Emu-5259/NeuralAI", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "Subject-Emu-5259/NeuralAI" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Subject-Emu-5259/NeuralAI", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Subject-Emu-5259/NeuralAI with Docker Model Runner:
docker model run hf.co/Subject-Emu-5259/NeuralAI
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig, TrainingArguments, Trainer, DataCollatorForLanguageModeling, BitsAndBytesConfig | |
| from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training | |
| from datasets import load_dataset | |
| def train(): | |
| model_id = 'HuggingFaceTB/SmolLM2-360M-Instruct' | |
| # 1. Load Tokenizer | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| tokenizer.pad_token = tokenizer.eos_token | |
| # 2. Config & Model | |
| bnb_config = BitsAndBytesConfig( | |
| load_in_4bit=True, | |
| bnb_4bit_quant_type='nf4', | |
| bnb_4bit_compute_dtype=torch.bfloat16, | |
| bnb_4bit_use_double_quant=True | |
| ) | |
| config = AutoConfig.from_pretrained(model_id) | |
| config.use_cache = False | |
| config._attn_implementation = 'sdpa' | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_id, | |
| config=config, | |
| quantization_config=bnb_config, | |
| device_map='auto', | |
| trust_remote_code=True | |
| ) | |
| model = prepare_model_for_kbit_training(model) | |
| # 3. LoRA Setup | |
| peft_config = LoraConfig( | |
| r=16, | |
| lora_alpha=32, | |
| target_modules=['q_proj', 'k_proj', 'v_proj', 'o_proj'], | |
| lora_dropout=0.05, | |
| bias='none', | |
| task_type='CAUSAL_LM' | |
| ) | |
| model = get_peft_model(model, peft_config) | |
| # 4. Data Loading & Formatting | |
| dataset = load_dataset('json', data_files='./data/train.jsonl', split='train') | |
| def formatting_func(example): | |
| # Handle standard ChatML or instruction formats | |
| if example.get('messages') is not None: | |
| try: | |
| return tokenizer.apply_chat_template(example['messages'], tokenize=False, add_generation_prompt=False) | |
| except Exception: | |
| return "" | |
| elif example.get('instruction') and example.get('response'): | |
| return f"<|user|>\n{example['instruction']}<|endoftext|>\n<|assistant|>\n{example['response']}<|endoftext|>" | |
| elif example.get('text'): | |
| return example['text'] | |
| return "" | |
| def tokenize(example): | |
| text = formatting_func(example) | |
| # If the result is empty, use a dummy string to avoid training errors | |
| if not text: | |
| text = tokenizer.eos_token | |
| return tokenizer(text, truncation=True, max_length=512, padding='max_length') | |
| tokenized_dataset = dataset.map(tokenize, remove_columns=dataset.column_names) | |
| # 5. Training | |
| args = TrainingArguments( | |
| output_dir='./checkpoints', | |
| num_train_epochs=3, | |
| per_device_train_batch_size=4, | |
| gradient_accumulation_steps=4, | |
| learning_rate=2e-4, | |
| fp16=True, | |
| logging_steps=10, | |
| save_strategy='epoch', | |
| optim='paged_adamw_32bit' | |
| ) | |
| trainer = Trainer( | |
| model=model, | |
| train_dataset=tokenized_dataset, | |
| args=args, | |
| data_collator=DataCollatorForLanguageModeling(tokenizer, mlm=False) | |
| ) | |
| print('Starting training...') | |
| trainer.train() | |
| model.save_pretrained('./checkpoints/final_model') | |
| print('Training complete!') | |
| if __name__ == '__main__': | |
| train() | |