Text Generation
Transformers
Safetensors
Upper Grand Valley Dani
llama
genomic
text-generation-inference
Instructions to use HuggingFaceBio/Carbon-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HuggingFaceBio/Carbon-3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="HuggingFaceBio/Carbon-3B")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("HuggingFaceBio/Carbon-3B") model = AutoModelForCausalLM.from_pretrained("HuggingFaceBio/Carbon-3B") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use HuggingFaceBio/Carbon-3B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HuggingFaceBio/Carbon-3B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HuggingFaceBio/Carbon-3B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/HuggingFaceBio/Carbon-3B
- SGLang
How to use HuggingFaceBio/Carbon-3B 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 "HuggingFaceBio/Carbon-3B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HuggingFaceBio/Carbon-3B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "HuggingFaceBio/Carbon-3B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HuggingFaceBio/Carbon-3B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use HuggingFaceBio/Carbon-3B with Docker Model Runner:
docker model run hf.co/HuggingFaceBio/Carbon-3B
Update README.md
Browse files
README.md
CHANGED
|
@@ -133,6 +133,41 @@ def score(seq: str) -> float:
|
|
| 133 |
targets = ids[:, 1:]
|
| 134 |
logp = F.log_softmax(logits.float(), dim=-1).gather(-1, targets.unsqueeze(-1)).squeeze(-1)
|
| 135 |
return logp.mean().item()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
```
|
| 137 |
|
| 138 |
For batched scoring with attention masking and full reproducible evaluation pipelines (sequence recovery, ClinVar / BRCA2 / TraitGym VEP, TATA / synonymous-codon perturbation, Genome-NIAH), use the official scripts in the [Carbon evaluation directory](https://github.com/huggingface/carbon/tree/main/evaluation) — see [`perturbation_tasks.py`](https://github.com/huggingface/carbon/blob/main/evaluation/perturbation_tasks.py) for the canonical `score_hf` implementation and [`README.md`](https://github.com/huggingface/carbon/blob/main/evaluation/README.md) for run instructions across all tasks.
|
|
|
|
| 133 |
targets = ids[:, 1:]
|
| 134 |
logp = F.log_softmax(logits.float(), dim=-1).gather(-1, targets.unsqueeze(-1)).squeeze(-1)
|
| 135 |
return logp.mean().item()
|
| 136 |
+
|
| 137 |
+
# QY: not sure if we still want to keep this per-token log-probabilities score function,
|
| 138 |
+
# because we now have a more elegant one in modeling_carbon.py:
|
| 139 |
+
import torch
|
| 140 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 141 |
+
|
| 142 |
+
repo = "HuggingFaceBio/Carbon-3B"
|
| 143 |
+
|
| 144 |
+
# Load tokenizer and model
|
| 145 |
+
tok = AutoTokenizer.from_pretrained(repo, trust_remote_code=True)
|
| 146 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 147 |
+
repo,
|
| 148 |
+
torch_dtype=torch.bfloat16,
|
| 149 |
+
trust_remote_code=True
|
| 150 |
+
).cuda().eval()
|
| 151 |
+
|
| 152 |
+
# Setup tokenizer for bp-level scoring (required for score_sequence)
|
| 153 |
+
model.setup_tokenizer(tok)
|
| 154 |
+
|
| 155 |
+
# Score sequences - automatically handles BOS token and padding
|
| 156 |
+
sequences = ["ATCG" * 1024, "ACAT" * 2048]
|
| 157 |
+
bp_probs_list, actual_probs_list = model.score_sequence(sequences)
|
| 158 |
+
|
| 159 |
+
# bp_probs_list: list of [seq_len_i, 4] tensors - probability distribution over A/T/C/G at each position
|
| 160 |
+
# actual_probs_list: list of [seq_len_i] tensors - probability of the actual base at each position
|
| 161 |
+
|
| 162 |
+
# Compute metrics for each sequence
|
| 163 |
+
for i, (seq, actual_probs) in enumerate(zip(sequences, actual_probs_list)):
|
| 164 |
+
log_likelihood = actual_probs.log().sum().item() # Total log-likelihood
|
| 165 |
+
perplexity = torch.exp(-actual_probs.log().mean()).item() # Perplexity
|
| 166 |
+
|
| 167 |
+
print(f"Sequence {i+1} (length {len(seq)}):")
|
| 168 |
+
print(f" Log-likelihood: {log_likelihood:.2f}")
|
| 169 |
+
print(f" Perplexity: {perplexity:.4f}")
|
| 170 |
+
print(f" Mean probability: {actual_probs.mean().item():.4f}")
|
| 171 |
```
|
| 172 |
|
| 173 |
For batched scoring with attention masking and full reproducible evaluation pipelines (sequence recovery, ClinVar / BRCA2 / TraitGym VEP, TATA / synonymous-codon perturbation, Genome-NIAH), use the official scripts in the [Carbon evaluation directory](https://github.com/huggingface/carbon/tree/main/evaluation) — see [`perturbation_tasks.py`](https://github.com/huggingface/carbon/blob/main/evaluation/perturbation_tasks.py) for the canonical `score_hf` implementation and [`README.md`](https://github.com/huggingface/carbon/blob/main/evaluation/README.md) for run instructions across all tasks.
|