AlfredPros/smart-contracts-instructions
Viewer • Updated • 6k • 86 • 6
How to use braindao/iq-code-evmind-v1-granite-8b-instruct with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="braindao/iq-code-evmind-v1-granite-8b-instruct")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("braindao/iq-code-evmind-v1-granite-8b-instruct")
model = AutoModelForCausalLM.from_pretrained("braindao/iq-code-evmind-v1-granite-8b-instruct")
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 braindao/iq-code-evmind-v1-granite-8b-instruct with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "braindao/iq-code-evmind-v1-granite-8b-instruct"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "braindao/iq-code-evmind-v1-granite-8b-instruct",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/braindao/iq-code-evmind-v1-granite-8b-instruct
How to use braindao/iq-code-evmind-v1-granite-8b-instruct with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "braindao/iq-code-evmind-v1-granite-8b-instruct" \
--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": "braindao/iq-code-evmind-v1-granite-8b-instruct",
"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 "braindao/iq-code-evmind-v1-granite-8b-instruct" \
--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": "braindao/iq-code-evmind-v1-granite-8b-instruct",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use braindao/iq-code-evmind-v1-granite-8b-instruct with Docker Model Runner:
docker model run hf.co/braindao/iq-code-evmind-v1-granite-8b-instruct
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
model_path = "braindao/iq-code-evmind-v1-granite-8b-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, device_map=device)
model.eval()
chat = [
{
"role": "user",
"content": "Create a smart contract to serve as a centralized review system called ReviewHub. This contract should allow users to submit and manage reviews for various products or services, rate them on a scale of 1 to 5, and provide detailed comments. It should include functionalities for assigning unique identifiers to products or services, storing and retrieving reviews, allowing users to edit or delete their reviews, calculating average ratings, and enabling an administrator to moderate content. The contract must incorporate robust security measures to ensure review integrity and prevent spam or malicious activity."
},
]
chat = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
input_tokens = tokenizer(chat, return_tensors="pt")
for i in input_tokens:
input_tokens[i] = input_tokens[i].to(device)
output = model.generate(**input_tokens, max_new_tokens=4096)
output = tokenizer.batch_decode(output)
for i in output:
print(i)