Text Generation
Transformers
Safetensors
Upper Grand Valley Dani
llama
genomic
speculative-decoding
text-generation-inference
Instructions to use HuggingFaceBio/Carbon-500M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HuggingFaceBio/Carbon-500M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="HuggingFaceBio/Carbon-500M")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("HuggingFaceBio/Carbon-500M") model = AutoModelForCausalLM.from_pretrained("HuggingFaceBio/Carbon-500M", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use HuggingFaceBio/Carbon-500M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HuggingFaceBio/Carbon-500M" # 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-500M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/HuggingFaceBio/Carbon-500M
- SGLang
How to use HuggingFaceBio/Carbon-500M 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-500M" \ --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-500M", "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-500M" \ --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-500M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use HuggingFaceBio/Carbon-500M with Docker Model Runner:
docker model run hf.co/HuggingFaceBio/Carbon-500M
tokenizer: fix EOS append bug, decode skip_special_tokens=True, add auto_dna_tags
Browse files7 unmodified lines89101112131411 unmodified lines2627282930312 unmodified lines34353637383923 unmodified lines636465666768159 unmodified lines22822923023123223331 unmodified lines26526626726826927027127236 unmodified lines30931031131231331431531631731838 unmodified lines35735835936036136236336 unmodified lines4004014024034044054 unmodified lines41041141241341441541641741841942075 unmodified lines49649749849950050115 unmodified lines51751851952052152210 unmodified lines5335345355365375385395405415425435445455465475485495505517 unmodified lines-2: padding token-1: text token (BPE)0: DNA special token (<dna>, </dna>, <oov>)1-5: partial 6-mer (number of valid bases)6: full 6-mer"""11 unmodified linesDNA regions must be wrapped in <dna>...</dna> tags to be tokenized as 6-mers.Without tags, DNA sequences are tokenized as regular BPE text."""model_input_names = ["input_ids", "attention_mask"]2 unmodified linesself,base_tokenizer_path: Optional[str] = None,k: int = 6,**kwargs):self.k = k23 unmodified lines)self.special_tokens = self.dna_special_tokens + [self._eos_token, self._pad_token]def _init_dna_vocab(self):"""Initialize DNA vocabulary (special tokens + k-mers + padding for 128 alignment)."""159 unmodified linesif remaining:padding_needed = k - len(remaining)padded = remaining + 'A' * padding_neededif is_valid_kmer(padded):31 unmodified linestext: str,add_special_tokens: bool = False,return_token_mask: bool = False,**kwargs) -> Union[List[int], Tuple[List[int], List[int]]]:segments = self._split_by_dna_tags(text)token_ids = []36 unmodified linesif return_token_mask:token_mask.extend([-1] * len(base_ids))if add_special_tokens and self.eos_token_id is not None:token_ids.append(self.eos_token_id)if return_token_mask:token_mask.append(-1)if return_token_mask:return token_ids, token_mask38 unmodified linesi += 1elif tid in self.dna_id_to_token:if not skip_special_tokens:parts.append(self.dna_id_to_token[tid])i += 136 unmodified linesmax_length: Optional[int] = None,return_tensors: Optional[str] = None,return_token_mask: bool = False,**kwargs) -> Dict[str, Any]:is_batch = isinstance(text, list)4 unmodified linesfor t in texts:if return_token_mask:ids, mask = self.encode(t, add_special_tokens=add_special_tokens, return_token_mask=True)all_ids.append(ids)all_masks.append(mask)else:ids = self.encode(t, add_special_tokens=add_special_tokens, return_token_mask=False)all_ids.append(ids)if padding:75 unmodified lines"dna_start_id": self.dna_start_id,"dna_vocab_size": self.dna_vocab_size,"dna_special_tokens": self.dna_special_tokens,}dna_config_path = os.path.join(save_directory, "dna_config.json")15 unmodified lines"AutoTokenizer": ["tokenizer.HybridDNATokenizer", None]},"k": self.k,})with open(config_path, "w", encoding="utf-8") as f:10 unmodified lines@classmethoddef from_pretrained(cls, pretrained_model_name_or_path: str, **kwargs):dna_config_path = os.path.join(pretrained_model_name_or_path, "dna_config.json")if os.path.exists(dna_config_path):with open(dna_config_path, "r") as f:dna_config = json.load(f)k = dna_config.get("k", 6)else:config_path = os.path.join(pretrained_model_name_or_path, "tokenizer_config.json")if os.path.exists(config_path):with open(config_path, "r") as f:config = json.load(f)k = config.get("k", 6)else:k = 6return cls(base_tokenizer_path=pretrained_model_name_or_path, k=k, **kwargs)7 unmodified lines891011121314151611 unmodified lines2829303132333435363738392 unmodified lines4243444546474823 unmodified lines72737475767778159 unmodified lines23823924024124224324424524624731 unmodified lines27928028128228328428528628728828929029136 unmodified lines32832933033133233333433533633733838 unmodified lines37737837938038138238338438538638738838939036 unmodified lines4274284294304314324334 unmodified lines43843944044144244344444544644744875 unmodified lines52452552652752852953015 unmodified lines54654754854955055155210 unmodified lines5635645655665675685695705715725735745755765775785795805815825837 unmodified lines-2: padding token-1: text token (BPE)0: DNA special token (<dna>, </dna>, <oov>)1-5: partial 6-mer token — valid_length real bases at positions [0, valid_length),right-padded with 'A' at positions [valid_length, k) so loss can supervisepositions 0..valid_len-1 via pos_mask = (valid_len > pos)6: full 6-mer"""11 unmodified linesDNA regions must be wrapped in <dna>...</dna> tags to be tokenized as 6-mers.Without tags, DNA sequences are tokenized as regular BPE text.For pure-DNA input (no metadata tokens), pass auto_dna_tags=True to have<dna>...</dna> tags added automatically when they are absent. Do NOT setthis if the input may contain BPE metadata such as species tags(<fungi_species> etc.) — those must appear outside <dna>...</dna> and wouldbe incorrectly k-mer encoded if auto-wrapping fired."""model_input_names = ["input_ids", "attention_mask"]2 unmodified linesself,base_tokenizer_path: Optional[str] = None,k: int = 6,auto_dna_tags: bool = False,**kwargs):self.k = k23 unmodified lines)self.special_tokens = self.dna_special_tokens + [self._eos_token, self._pad_token]self.auto_dna_tags = auto_dna_tagsdef _init_dna_vocab(self):"""Initialize DNA vocabulary (special tokens + k-mers + padding for 128 alignment)."""159 unmodified linesif remaining:padding_needed = k - len(remaining)# Right-pad with A: real bases occupy positions [0, valid_length).# The hybrid BP loss supervises positions 0..valid_len-1 via# pos_mask = (valid_len > pos)# so padding must be at the END, not the start.padded = remaining + 'A' * padding_neededif is_valid_kmer(padded):31 unmodified linestext: str,add_special_tokens: bool = False,return_token_mask: bool = False,auto_dna_tags: Optional[bool] = None,**kwargs) -> Union[List[int], Tuple[List[int], List[int]]]:use_auto = self.auto_dna_tags if auto_dna_tags is None else auto_dna_tagsif use_auto and '<dna>' not in text:text = f'<dna>{text}</dna>'segments = self._split_by_dna_tags(text)token_ids = []36 unmodified linesif return_token_mask:token_mask.extend([-1] * len(base_ids))# Do NOT append EOS when add_special_tokens=True. Qwen3 doesn't add# BOS/EOS either, and appending EOS here breaks lighteval's# tok_encode_pair: it relies on# len(encode(ctx)) + len(encode(answer)) == len(encode(ctx + answer))# which the extra EOS violates by shifting the split by 1.if return_token_mask:return token_ids, token_mask38 unmodified linesi += 1elif tid in self.dna_id_to_token:# This branch handles k-mer tokens that appear without a <dna># wrapper — the common generation case where <dna> was in the# prompt but only the generated portion is being decoded.# K-mer tokens are content, not special tokens, so always decode# them. Only drop true DNA special tokens (<dna>, </dna>, <oov>)# when skip_special_tokens=True.is_dna_special = tid in (self.dna_begin_token_id, self.dna_end_token_id, self.oov_token_id)if not (skip_special_tokens and is_dna_special):parts.append(self.dna_id_to_token[tid])i += 136 unmodified linesmax_length: Optional[int] = None,return_tensors: Optional[str] = None,return_token_mask: bool = False,auto_dna_tags: Optional[bool] = None,**kwargs) -> Dict[str, Any]:is_batch = isinstance(text, list)4 unmodified linesfor t in texts:if return_token_mask:ids, mask = self.encode(t, add_special_tokens=add_special_tokens, return_token_mask=True, auto_dna_tags=auto_dna_tags)all_ids.append(ids)all_masks.append(mask)else:ids = self.encode(t, add_special_tokens=add_special_tokens, return_token_mask=False, auto_dna_tags=auto_dna_tags)all_ids.append(ids)if padding:75 unmodified lines"dna_start_id": self.dna_start_id,"dna_vocab_size": self.dna_vocab_size,"dna_special_tokens": self.dna_special_tokens,"auto_dna_tags": self.auto_dna_tags,}dna_config_path = os.path.join(save_directory, "dna_config.json")15 unmodified lines"AutoTokenizer": ["tokenizer.HybridDNATokenizer", None]},"k": self.k,"auto_dna_tags": self.auto_dna_tags,})with open(config_path, "w", encoding="utf-8") as f:10 unmodified lines@classmethoddef from_pretrained(cls, pretrained_model_name_or_path: str, **kwargs):k = 6auto_dna_tags = Falsedna_config_path = os.path.join(pretrained_model_name_or_path, "dna_config.json")tok_config_path = os.path.join(pretrained_model_name_or_path, "tokenizer_config.json")if os.path.exists(dna_config_path):with open(dna_config_path, "r") as f:dna_config = json.load(f)k = dna_config.get("k", 6)auto_dna_tags = dna_config.get("auto_dna_tags", False)elif os.path.exists(tok_config_path):with open(tok_config_path, "r") as f:tok_config = json.load(f)k = tok_config.get("k", 6)auto_dna_tags = tok_config.get("auto_dna_tags", False)return cls(base_tokenizer_path=pretrained_model_name_or_path, k=k, auto_dna_tags=auto_dna_tags, **kwargs)
tokenizer.py+50-18