Instructions to use lamm-mit/BioinspiredZephyr-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lamm-mit/BioinspiredZephyr-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lamm-mit/BioinspiredZephyr-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("lamm-mit/BioinspiredZephyr-7B") model = AutoModelForCausalLM.from_pretrained("lamm-mit/BioinspiredZephyr-7B") 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]:])) - llama-cpp-python
How to use lamm-mit/BioinspiredZephyr-7B with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="lamm-mit/BioinspiredZephyr-7B", filename="ggml-model-f16.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use lamm-mit/BioinspiredZephyr-7B with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf lamm-mit/BioinspiredZephyr-7B:Q4_K_M # Run inference directly in the terminal: llama-cli -hf lamm-mit/BioinspiredZephyr-7B:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf lamm-mit/BioinspiredZephyr-7B:Q4_K_M # Run inference directly in the terminal: llama-cli -hf lamm-mit/BioinspiredZephyr-7B:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf lamm-mit/BioinspiredZephyr-7B:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf lamm-mit/BioinspiredZephyr-7B:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf lamm-mit/BioinspiredZephyr-7B:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf lamm-mit/BioinspiredZephyr-7B:Q4_K_M
Use Docker
docker model run hf.co/lamm-mit/BioinspiredZephyr-7B:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use lamm-mit/BioinspiredZephyr-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lamm-mit/BioinspiredZephyr-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lamm-mit/BioinspiredZephyr-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/lamm-mit/BioinspiredZephyr-7B:Q4_K_M
- SGLang
How to use lamm-mit/BioinspiredZephyr-7B 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 "lamm-mit/BioinspiredZephyr-7B" \ --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": "lamm-mit/BioinspiredZephyr-7B", "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 "lamm-mit/BioinspiredZephyr-7B" \ --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": "lamm-mit/BioinspiredZephyr-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use lamm-mit/BioinspiredZephyr-7B with Ollama:
ollama run hf.co/lamm-mit/BioinspiredZephyr-7B:Q4_K_M
- Unsloth Studio
How to use lamm-mit/BioinspiredZephyr-7B with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
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 lamm-mit/BioinspiredZephyr-7B to start chatting
Install Unsloth Studio (Windows)
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 lamm-mit/BioinspiredZephyr-7B to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for lamm-mit/BioinspiredZephyr-7B to start chatting
- Docker Model Runner
How to use lamm-mit/BioinspiredZephyr-7B with Docker Model Runner:
docker model run hf.co/lamm-mit/BioinspiredZephyr-7B:Q4_K_M
- Lemonade
How to use lamm-mit/BioinspiredZephyr-7B with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull lamm-mit/BioinspiredZephyr-7B:Q4_K_M
Run and chat with the model
lemonade run user.BioinspiredZephyr-7B-Q4_K_M
List all available models
lemonade list
Update README.md
Browse files
README.md
CHANGED
|
@@ -15,6 +15,81 @@ This model is based on work reported in https://doi.org/10.1002/advs.202306724.
|
|
| 15 |
|
| 16 |
This repository includes both, Hugging Face transformers and GGUF files (in different versions, the q5_K_M is recommended).
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
```
|
| 19 |
from llama_cpp import Llama
|
| 20 |
|
|
@@ -80,4 +155,4 @@ deltat=time.time() - start_time
|
|
| 80 |
print("--- %s seconds ---" % deltat)
|
| 81 |
toked=tokenizer(res)
|
| 82 |
print ("Tokens per second (generation): ", len (toked['input_ids'])/deltat)
|
| 83 |
-
```
|
|
|
|
| 15 |
|
| 16 |
This repository includes both, Hugging Face transformers and GGUF files (in different versions, the q5_K_M is recommended).
|
| 17 |
|
| 18 |
+
#### Hugging Face transformers files: Loading and inference
|
| 19 |
+
|
| 20 |
+
```
|
| 21 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 22 |
+
from accelerate import infer_auto_device_map
|
| 23 |
+
|
| 24 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 25 |
+
model_name,
|
| 26 |
+
trust_remote_code=True,
|
| 27 |
+
device_map="auto", #device_map="cuda:0",
|
| 28 |
+
torch_dtype= torch.bfloat16,
|
| 29 |
+
# use_flash_attention_2=True,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 33 |
+
```
|
| 34 |
+
Chat template
|
| 35 |
+
```
|
| 36 |
+
messages = [
|
| 37 |
+
{"role": "system", "content": "You are a friendly materials scientist."},
|
| 38 |
+
{"role": "user", "content": "What is the strongest spider silk material?"},
|
| 39 |
+
{"role": "assistant", "content": "Sample response."},
|
| 40 |
+
]
|
| 41 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
'<|system|>\nYou are a friendly materials scientist.</s>\n<|user|>\nWhat is the strongest spider silk material?</s>\n<|assistant|>\nSample response.</s>\n<|assistant|>\n'
|
| 45 |
+
|
| 46 |
+
```
|
| 47 |
+
device='cuda'
|
| 48 |
+
def generate_response (text_input="Biological materials offer amazing possibilities, such as",
|
| 49 |
+
num_return_sequences=1,
|
| 50 |
+
temperature=1.,
|
| 51 |
+
max_new_tokens=127,
|
| 52 |
+
num_beams=1,
|
| 53 |
+
top_k = 50,
|
| 54 |
+
top_p =0.9,repetition_penalty=1.,eos_token_id=2,verbatim=False,
|
| 55 |
+
exponential_decay_length_penalty_fac=None,
|
| 56 |
+
):
|
| 57 |
+
|
| 58 |
+
inputs = tokenizer.encode(text_input, add_special_tokens =False, return_tensors ='pt')
|
| 59 |
+
if verbatim:
|
| 60 |
+
print ("Length of input, tokenized: ", inputs.shape, inputs)
|
| 61 |
+
with torch.no_grad():
|
| 62 |
+
outputs = model.generate(input_ids=inputs.to(device),
|
| 63 |
+
max_new_tokens=max_new_tokens,
|
| 64 |
+
temperature=temperature, #value used to modulate the next token probabilities.
|
| 65 |
+
num_beams=num_beams,
|
| 66 |
+
top_k = top_k,
|
| 67 |
+
top_p =top_p,
|
| 68 |
+
num_return_sequences = num_return_sequences, eos_token_id=eos_token_id,
|
| 69 |
+
do_sample =True,
|
| 70 |
+
repetition_penalty=repetition_penalty,
|
| 71 |
+
)
|
| 72 |
+
return tokenizer.batch_decode(outputs[:,inputs.shape[1]:].detach().cpu().numpy(), skip_special_tokens=True)
|
| 73 |
+
|
| 74 |
+
```
|
| 75 |
+
Then:
|
| 76 |
+
```
|
| 77 |
+
messages = [
|
| 78 |
+
{"role": "system", "content": "You are a friendly materials scientist."},
|
| 79 |
+
{"role": "user", "content": "What is the strongest spider silk material?"},
|
| 80 |
+
]
|
| 81 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 82 |
+
|
| 83 |
+
output_text=generate_response (text_input=prompt, eos_token_id=eos_token,
|
| 84 |
+
num_return_sequences=1, repetition_penalty=1.,
|
| 85 |
+
top_p=0.9, top_k=512,
|
| 86 |
+
temperature=0.1,max_new_tokens=512, verbatim=False,
|
| 87 |
+
)
|
| 88 |
+
print (output_text)
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
#### GGUF files: Loading and inference
|
| 92 |
+
|
| 93 |
```
|
| 94 |
from llama_cpp import Llama
|
| 95 |
|
|
|
|
| 155 |
print("--- %s seconds ---" % deltat)
|
| 156 |
toked=tokenizer(res)
|
| 157 |
print ("Tokens per second (generation): ", len (toked['input_ids'])/deltat)
|
| 158 |
+
```
|