gbharti/finance-alpaca
Viewer • Updated • 68.9k • 2.49k • 146
How to use umarigan/llama3.2-1B-fin with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="umarigan/llama3.2-1B-fin")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("umarigan/llama3.2-1B-fin")
model = AutoModelForCausalLM.from_pretrained("umarigan/llama3.2-1B-fin")
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]:]))How to use umarigan/llama3.2-1B-fin with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "umarigan/llama3.2-1B-fin"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "umarigan/llama3.2-1B-fin",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/umarigan/llama3.2-1B-fin
How to use umarigan/llama3.2-1B-fin with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "umarigan/llama3.2-1B-fin" \
--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": "umarigan/llama3.2-1B-fin",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'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 "umarigan/llama3.2-1B-fin" \
--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": "umarigan/llama3.2-1B-fin",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use umarigan/llama3.2-1B-fin with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for umarigan/llama3.2-1B-fin to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for umarigan/llama3.2-1B-fin to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for umarigan/llama3.2-1B-fin to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="umarigan/llama3.2-1B-fin",
max_seq_length=2048,
)How to use umarigan/llama3.2-1B-fin with Docker Model Runner:
docker model run hf.co/umarigan/llama3.2-1B-fin
Small model for finance use cases fine-tuned on a QA dataset. Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("umarigan/llama3.2-1B-fin")
model = AutoModelForCausalLM.from_pretrained("umarigan/llama3.2-1B-fin")
alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
{}"""
inputs = tokenizer(
[
alpaca_prompt.format(
"How this article will effect stock price of Pfizer", # Görev
"""(Reuters) -Drugmaker Pfizer on Tuesday said it was expecting its 2025 profits to be nearly in line with Wall Street expectations as it seeks to fend off criticism over its turnaround strategy from activist hedge fund Starboard Value.
Shares of the company rose nearly 3% in premarket trading.
The company expects adjusted profit of $2.80 to $3 per share, compared with analysts' average estimate of $2.88 per share, according to data compiled by LSEG.
Pfizer has been reining in costs and cutting debt by shedding non-core businesses as its rebuilds itself post a sharp slump in sales of COVID-19 products.
Its shares have fallen nearly 12% this year and trade at about half their value during the peak of the COVID-19 pandemic as revenue slows down and several top-selling drugs come off patent.
That has left it open to investor criticism, with Starboard in October saying that Pfizer's management has over-spent on big acquisitions and failed to produce profitable new drugs from those deals or from its internal research and development.
Pfizer forecast 2025 revenue in the range of $61 billion to $64 billion, compared with the estimates of $63.26 billion.
The company is slated to hold a conference call with analysts later in the day to discuss the forecast.
(Reporting by Mariam Sunny and Manas Mishra; Editing by Anil D'Silva)
""", # İnput
"", # Response - Leave empty!
)
], return_tensors = "pt")
outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
tokenizer.batch_decode(outputs)
Output:
### Response:\nPfizer is expected to see a significant increase in its profits in 2025.
The company is planning to hold a conference call with analysts later in the day to discuss the forecast.<|eot_id|>