Text Generation
Transformers
Safetensors
Hindi
English
parambharatgen
Ayurvedic
conversational
custom_code
Instructions to use bharatgenai/AyurParam with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use bharatgenai/AyurParam with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="bharatgenai/AyurParam", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("bharatgenai/AyurParam", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use bharatgenai/AyurParam with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "bharatgenai/AyurParam" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bharatgenai/AyurParam", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/bharatgenai/AyurParam
- SGLang
How to use bharatgenai/AyurParam 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 "bharatgenai/AyurParam" \ --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": "bharatgenai/AyurParam", "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 "bharatgenai/AyurParam" \ --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": "bharatgenai/AyurParam", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use bharatgenai/AyurParam with Docker Model Runner:
docker model run hf.co/bharatgenai/AyurParam
Update config_parambharatgen.py
#7
by 25f3001314 - opened
- config_parambharatgen.py +36 -56
config_parambharatgen.py
CHANGED
|
@@ -1,60 +1,40 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
hidden_size=2048,
|
| 11 |
-
intermediate_size=7168,
|
| 12 |
-
num_hidden_layers=32,
|
| 13 |
-
num_attention_heads=16,
|
| 14 |
-
num_key_value_heads=8,
|
| 15 |
-
hidden_act="silu",
|
| 16 |
-
max_position_embeddings=2048,
|
| 17 |
-
initializer_range=0.01,
|
| 18 |
-
rms_norm_eps=1e-5,
|
| 19 |
-
use_cache=True,
|
| 20 |
-
pad_token_id=None,
|
| 21 |
-
bos_token_id=2,
|
| 22 |
-
eos_token_id=3,
|
| 23 |
-
pretraining_tp=1,
|
| 24 |
-
tie_word_embeddings=False,
|
| 25 |
-
rope_theta=10000.0,
|
| 26 |
-
rope_scaling=None,
|
| 27 |
-
attention_bias=False,
|
| 28 |
-
attention_dropout=0.0,
|
| 29 |
-
mlp_bias=False,
|
| 30 |
-
custom_mlp_ratio=3.5,
|
| 31 |
-
**kwargs,
|
| 32 |
-
):
|
| 33 |
-
self.vocab_size = vocab_size
|
| 34 |
-
self.max_position_embeddings = max_position_embeddings
|
| 35 |
-
self.hidden_size = hidden_size
|
| 36 |
-
self.intermediate_size = intermediate_size
|
| 37 |
-
self.num_hidden_layers = num_hidden_layers
|
| 38 |
-
self.num_attention_heads = num_attention_heads
|
| 39 |
-
self.num_key_value_heads = num_key_value_heads
|
| 40 |
-
self.hidden_act = hidden_act
|
| 41 |
-
self.initializer_range = initializer_range
|
| 42 |
-
self.rms_norm_eps = rms_norm_eps
|
| 43 |
-
self.pretraining_tp = pretraining_tp
|
| 44 |
-
self.use_cache = use_cache
|
| 45 |
-
self.rope_theta = rope_theta
|
| 46 |
-
self.rope_scaling = rope_scaling
|
| 47 |
-
self.attention_bias = attention_bias
|
| 48 |
-
self.attention_dropout = attention_dropout
|
| 49 |
-
self.mlp_bias = mlp_bias
|
| 50 |
-
self.custom_mlp_ratio = custom_mlp_ratio
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
bos_token_id=bos_token_id,
|
| 55 |
-
eos_token_id=eos_token_id,
|
| 56 |
-
tie_word_embeddings=tie_word_embeddings,
|
| 57 |
-
**kwargs,
|
| 58 |
-
)
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json, re, torch, spaces, gradio as gr
|
| 2 |
+
from huggingface_hub import snapshot_download
|
| 3 |
+
from transformers import AutoTokenizer, LlamaForCausalLM
|
| 4 |
|
| 5 |
+
path = snapshot_download("bharatgenai/AyurParam", local_dir="ayurparam",
|
| 6 |
+
ignore_patterns=["*.py"])
|
| 7 |
+
cfg = json.load(open(f"{path}/config.json"))
|
| 8 |
+
cfg["architectures"] = ["LlamaForCausalLM"]
|
| 9 |
+
cfg["model_type"] = "llama"
|
| 10 |
+
cfg.pop("auto_map", None)
|
| 11 |
+
json.dump(cfg, open(f"{path}/config.json", "w"), indent=2)
|
| 12 |
|
| 13 |
+
tok = AutoTokenizer.from_pretrained(path)
|
| 14 |
+
model = LlamaForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16)
|
| 15 |
+
model.eval()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
RISKY_WORDS = ["upay", "ilaj", "upchar", "cure", "bukhar", "fever", "dard", "pain",
|
| 18 |
+
"stress", "udaas", "akela", "depress", "chinta", "dawai", "medicine"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
def clean_answer(text):
|
| 21 |
+
return re.split(r"\s0[A-Za-z]?:", text)[0].strip()
|
| 22 |
+
|
| 23 |
+
@spaces.GPU
|
| 24 |
+
def chat(message, history):
|
| 25 |
+
if any(w in message.lower() for w in RISKY_WORDS):
|
| 26 |
+
return ("Main sirf Ayurveda ke concepts (dosha, dincharya, jadi-booti, panchakarma) samjha sakta hoon. "
|
| 27 |
+
"Kisi bimari ya mansik tanaav ke liye kripya qualified doctor se salah lein.")
|
| 28 |
+
model.to("cuda")
|
| 29 |
+
prompt = ("तुम केवल आयुर्वेद के विषय में उत्तर देते हो, सिर्फ हिंदी में, संक्षेप में। "
|
| 30 |
+
"अगर सवाल आयुर्वेद से संबंधित नहीं है तो विनम्रता से मना करो।\n\n" + message)
|
| 31 |
+
msgs = [{"role": "user", "content": prompt}]
|
| 32 |
+
inp = tok.apply_chat_template(msgs, add_generation_prompt=True,
|
| 33 |
+
return_tensors="pt", return_dict=True).to("cuda")
|
| 34 |
+
out = model.generate(**inp, max_new_tokens=200, do_sample=True, temperature=0.4,
|
| 35 |
+
top_p=0.85, repetition_penalty=1.3, no_repeat_ngram_size=3)
|
| 36 |
+
answer = tok.decode(out[0][inp["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 37 |
+
return clean_answer(answer)
|
| 38 |
+
|
| 39 |
+
demo = gr.ChatInterface(chat, title="AyurParam")
|
| 40 |
+
demo.launch()
|