Instructions to use lifeofcoding/llama-3.2-3b-parser with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lifeofcoding/llama-3.2-3b-parser with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lifeofcoding/llama-3.2-3b-parser") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("lifeofcoding/llama-3.2-3b-parser") model = AutoModelForCausalLM.from_pretrained("lifeofcoding/llama-3.2-3b-parser", 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 lifeofcoding/llama-3.2-3b-parser with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lifeofcoding/llama-3.2-3b-parser" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lifeofcoding/llama-3.2-3b-parser", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/lifeofcoding/llama-3.2-3b-parser
- SGLang
How to use lifeofcoding/llama-3.2-3b-parser 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 "lifeofcoding/llama-3.2-3b-parser" \ --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": "lifeofcoding/llama-3.2-3b-parser", "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 "lifeofcoding/llama-3.2-3b-parser" \ --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": "lifeofcoding/llama-3.2-3b-parser", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use lifeofcoding/llama-3.2-3b-parser with Docker Model Runner:
docker model run hf.co/lifeofcoding/llama-3.2-3b-parser
Delete handler.py
Browse files- handler.py +0 -45
handler.py
DELETED
|
@@ -1,45 +0,0 @@
|
|
| 1 |
-
from typing import Any, Dict, List
|
| 2 |
-
|
| 3 |
-
import torch
|
| 4 |
-
import transformers
|
| 5 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 6 |
-
|
| 7 |
-
dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] == 8 else torch.float16
|
| 8 |
-
|
| 9 |
-
class EndpointHandler:
|
| 10 |
-
def __init__(self, path=""):
|
| 11 |
-
tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
|
| 12 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 13 |
-
path,
|
| 14 |
-
return_dict=True,
|
| 15 |
-
device_map="auto",
|
| 16 |
-
load_in_8bit=False,
|
| 17 |
-
torch_dtype=dtype,
|
| 18 |
-
trust_remote_code=True,
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
-
generation_config = model.generation_config
|
| 22 |
-
generation_config.max_new_tokens = 10000
|
| 23 |
-
generation_config.temperature = 0.01
|
| 24 |
-
generation_config.num_return_sequences = 1
|
| 25 |
-
generation_config.pad_token_id = tokenizer.eos_token_id
|
| 26 |
-
generation_config.eos_token_id = tokenizer.eos_token_id
|
| 27 |
-
self.generation_config = generation_config
|
| 28 |
-
|
| 29 |
-
self.pipeline = transformers.pipeline(
|
| 30 |
-
"text-generation", model=model, tokenizer=tokenizer
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
def __call__(self, data: Dist[str, Any]) -> Dict[str, Any]:
|
| 34 |
-
prompt = data.pop("inputs", data)
|
| 35 |
-
|
| 36 |
-
system_message = """
|
| 37 |
-
You are an expert at analyzing the text of narrative scenes. Only respond with complete JSON responses beginning with [ and end with ]. Do not add new lines Separate the text of the scene to analyze into passages spoken aloud by a character from text not spoken aloud by a character. Identify the character speaking, and the tone being used. To help identify dialog, we have turned all quotation marks into the string SPOOOOOOKEN. For example the sentence SPOOOOOOKENHello, Janet,SPOOOOOOKEN John growled angrily. would result in the following output format: [{"position": 1, "type": "dialog", "narrator": "John", "tone": "angry", "content": "SPOOOOOOKENHello, Janet,SPOOOOOOKEN "}, {"position": 2, "type": "narration", "narrator": "Narrator", "tone": "", "content": "John growled angrily."}] If there is a new-line character, separate it as its own json object. Here is the scene to analyze:
|
| 38 |
-
""".strip()
|
| 39 |
-
|
| 40 |
-
messages = [
|
| 41 |
-
{"role": "system", "content": system_message},
|
| 42 |
-
{"role": "user", "content": prompt},
|
| 43 |
-
]
|
| 44 |
-
result = self.pipeline(messages, generation_config=self.generation_config)
|
| 45 |
-
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|