Text Generation
PEFT
Safetensors
Transformers
qwen2
lora
coding
code-generation
conversational
text-generation-inference
Instructions to use girish00/ConicAI_LLM_model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use girish00/ConicAI_LLM_model with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-0.5B-Instruct") model = PeftModel.from_pretrained(base_model, "girish00/ConicAI_LLM_model") - Transformers
How to use girish00/ConicAI_LLM_model with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="girish00/ConicAI_LLM_model") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("girish00/ConicAI_LLM_model") model = AutoModelForCausalLM.from_pretrained("girish00/ConicAI_LLM_model") 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
- vLLM
How to use girish00/ConicAI_LLM_model with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "girish00/ConicAI_LLM_model" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "girish00/ConicAI_LLM_model", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/girish00/ConicAI_LLM_model
- SGLang
How to use girish00/ConicAI_LLM_model 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 "girish00/ConicAI_LLM_model" \ --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": "girish00/ConicAI_LLM_model", "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 "girish00/ConicAI_LLM_model" \ --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": "girish00/ConicAI_LLM_model", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use girish00/ConicAI_LLM_model with Docker Model Runner:
docker model run hf.co/girish00/ConicAI_LLM_model
add cloud structured inference wrapper
Browse files- infer_cloud.py +110 -0
infer_cloud.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
import requests
|
| 7 |
+
from huggingface_hub import InferenceClient, get_token
|
| 8 |
+
|
| 9 |
+
from infer_local import build_instruction_prompt, build_structured_result
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def normalize_hf_response(response):
|
| 13 |
+
if isinstance(response, str):
|
| 14 |
+
return response
|
| 15 |
+
|
| 16 |
+
generated_text = getattr(response, "generated_text", None)
|
| 17 |
+
if generated_text is not None:
|
| 18 |
+
return generated_text
|
| 19 |
+
|
| 20 |
+
if isinstance(response, list) and response:
|
| 21 |
+
first = response[0]
|
| 22 |
+
if isinstance(first, dict):
|
| 23 |
+
return str(first.get("generated_text", ""))
|
| 24 |
+
return str(first)
|
| 25 |
+
|
| 26 |
+
if isinstance(response, dict):
|
| 27 |
+
return str(response.get("generated_text", response.get("text", "")))
|
| 28 |
+
|
| 29 |
+
return str(response)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def call_direct_inference_api(repo_id, token, prompt_text, generation_kwargs):
|
| 33 |
+
headers = {}
|
| 34 |
+
if token:
|
| 35 |
+
headers["Authorization"] = f"Bearer {token}"
|
| 36 |
+
|
| 37 |
+
payload = {
|
| 38 |
+
"inputs": prompt_text,
|
| 39 |
+
"parameters": generation_kwargs,
|
| 40 |
+
"options": {"wait_for_model": True},
|
| 41 |
+
}
|
| 42 |
+
response = requests.post(
|
| 43 |
+
f"https://api-inference.huggingface.co/models/{repo_id}",
|
| 44 |
+
headers=headers,
|
| 45 |
+
json=payload,
|
| 46 |
+
timeout=120,
|
| 47 |
+
)
|
| 48 |
+
try:
|
| 49 |
+
body = response.json()
|
| 50 |
+
except ValueError:
|
| 51 |
+
body = response.text
|
| 52 |
+
|
| 53 |
+
if response.status_code >= 400:
|
| 54 |
+
raise RuntimeError(f"Hugging Face API error {response.status_code}: {body}")
|
| 55 |
+
if isinstance(body, dict) and body.get("error"):
|
| 56 |
+
raise RuntimeError(f"Hugging Face API error: {body['error']}")
|
| 57 |
+
return body
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def main():
|
| 61 |
+
parser = argparse.ArgumentParser()
|
| 62 |
+
parser.add_argument("--repo-id", type=str, required=True)
|
| 63 |
+
parser.add_argument("--prompt", type=str, required=True)
|
| 64 |
+
parser.add_argument("--token", type=str, default=os.getenv("HF_TOKEN"))
|
| 65 |
+
parser.add_argument("--max-new-tokens", type=int, default=320)
|
| 66 |
+
parser.add_argument("--temperature", type=float, default=0.25)
|
| 67 |
+
parser.add_argument("--top-p", type=float, default=0.9)
|
| 68 |
+
parser.add_argument("--do-sample", action="store_true")
|
| 69 |
+
args = parser.parse_args()
|
| 70 |
+
|
| 71 |
+
token = args.token or get_token()
|
| 72 |
+
client = InferenceClient(model=args.repo_id, token=token)
|
| 73 |
+
prompt_text = build_instruction_prompt(args.prompt)
|
| 74 |
+
|
| 75 |
+
generation_kwargs = {
|
| 76 |
+
"max_new_tokens": args.max_new_tokens,
|
| 77 |
+
"return_full_text": False,
|
| 78 |
+
}
|
| 79 |
+
if args.do_sample:
|
| 80 |
+
generation_kwargs["temperature"] = args.temperature
|
| 81 |
+
generation_kwargs["top_p"] = args.top_p
|
| 82 |
+
else:
|
| 83 |
+
generation_kwargs["temperature"] = 0.01
|
| 84 |
+
|
| 85 |
+
start_time = time.perf_counter()
|
| 86 |
+
try:
|
| 87 |
+
response = client.text_generation(prompt_text, **generation_kwargs)
|
| 88 |
+
except TypeError:
|
| 89 |
+
generation_kwargs.pop("return_full_text", None)
|
| 90 |
+
response = client.text_generation(prompt_text, **generation_kwargs)
|
| 91 |
+
except Exception:
|
| 92 |
+
response = call_direct_inference_api(args.repo_id, token, prompt_text, generation_kwargs)
|
| 93 |
+
latency_ms = int((time.perf_counter() - start_time) * 1000)
|
| 94 |
+
|
| 95 |
+
generated_text = normalize_hf_response(response).strip()
|
| 96 |
+
if generated_text.startswith(prompt_text):
|
| 97 |
+
generated_text = generated_text[len(prompt_text) :].strip()
|
| 98 |
+
generated_text = generated_text.replace("<|im_end|>", "").strip()
|
| 99 |
+
|
| 100 |
+
result = build_structured_result(
|
| 101 |
+
args.prompt,
|
| 102 |
+
generated_text,
|
| 103 |
+
latency_ms,
|
| 104 |
+
default_confidence=0.0,
|
| 105 |
+
)
|
| 106 |
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
if __name__ == "__main__":
|
| 110 |
+
main()
|