kunalchamoli/mental_health_v1
Viewer β’ Updated β’ 1k β’ 16
How to use aryan27/llama-therapy-lora with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf")
model = PeftModel.from_pretrained(base_model, "aryan27/llama-therapy-lora")How to use aryan27/llama-therapy-lora with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="aryan27/llama-therapy-lora") # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("aryan27/llama-therapy-lora", dtype="auto")How to use aryan27/llama-therapy-lora with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "aryan27/llama-therapy-lora"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "aryan27/llama-therapy-lora",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/aryan27/llama-therapy-lora
How to use aryan27/llama-therapy-lora with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "aryan27/llama-therapy-lora" \
--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": "aryan27/llama-therapy-lora",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "aryan27/llama-therapy-lora" \
--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": "aryan27/llama-therapy-lora",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use aryan27/llama-therapy-lora with Docker Model Runner:
docker model run hf.co/aryan27/llama-therapy-lora
It is a fine-tuned LLM built to simulate a therapist, trained on a dataset of therapy sessions.
It leverages Parameter-Efficient Fine-Tuning (PEFT) using LoRA (Low-Rank Adaptation) on Meta LLaMA 2 7B.
The model was fine-tuned on a Tesla T4 GPU, selectively training a small number of parameters to efficiently adapt the base model to the domain of mental health and therapy.
π‘ Dataset used is available on Hugging Face π€
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
# Load the base model in 4-bit precision
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_quant_type="nf4"
)
base_model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-2-7b-hf",
quantization_config=bnb_config,
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
# Load the adapter
model = PeftModel.from_pretrained(base_model, "aryan27/llama-therapy-lora")
# System prompt to guide behavior
system_prompt = (
"You are a compassionate and thoughtful therapist. "
"Your responses are empathetic, non-judgmental, and helpful."
)
# π§© Function to generate response
def generate_therapy_response(user_input: str):
prompt = f"{system_prompt}\nUser: {user_input}\nTherapist:"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=200,
do_sample=True,
temperature=0.7,
top_p=0.9,
repetition_penalty=1.1,
pad_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Strip off the prompt from the generated text
response_only = response.split("Therapist:")[-1].strip()
return response_only
# π¬ Example usage
response = generate_therapy_response("I feel demotivated because of my breakup")
print(response)