Instructions to use Salesforce/codegen25-7b-instruct_P with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Salesforce/codegen25-7b-instruct_P with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Salesforce/codegen25-7b-instruct_P")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen25-7b-instruct_P") model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen25-7b-instruct_P", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Salesforce/codegen25-7b-instruct_P with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Salesforce/codegen25-7b-instruct_P" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Salesforce/codegen25-7b-instruct_P", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Salesforce/codegen25-7b-instruct_P
- SGLang
How to use Salesforce/codegen25-7b-instruct_P 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 "Salesforce/codegen25-7b-instruct_P" \ --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": "Salesforce/codegen25-7b-instruct_P", "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 "Salesforce/codegen25-7b-instruct_P" \ --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": "Salesforce/codegen25-7b-instruct_P", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Salesforce/codegen25-7b-instruct_P with Docker Model Runner:
docker model run hf.co/Salesforce/codegen25-7b-instruct_P
Update tokenization_codegen25.py
Browse files3 unmodified lines4567891048 unmodified lines59606162636465666768697071727374757613 unmodified lines90919293949596979816 unmodified lines11511611711811912012111 unmodified lines1331341351361371381 unmodified line1401411421431441451461472 unmodified lines15015115215315415515685 unmodified lines2422432442453 unmodified lines# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/Apache-2.0"""Tokenization classes for CodeGen2.5."""from typing import List, Optionalfrom transformers.tokenization_utils import AddedToken, PreTrainedTokenizerfrom transformers.utils import logging48 unmodified lines]return fim_tokensdef include_codegen2_tokens():tokens = []tokens += [f"<dummy_{i}>" for i in range(4)]tokens.append("<sep>") # 50317tokens.append("<eom>") # 50318tokens += [f"<mask_{i}>" for i in reversed(range(1, 51199-50318+1))]return tokensadd_whitespaces = include_whitespace(n_min=2, n_max=32)add_tabs = include_tabs(n_min=2, n_max=10)fim_tokens = include_fim_tokens()codegen2_tokens = include_codegen2_tokens()tokenizer = tiktoken.get_encoding(base)13 unmodified linesfor sp in fim_tokens:special_tokens[sp] = idxidx += 1for sp in codegen2_tokens:special_tokens[sp] = idxidx += 1if pad_token and pad_token not in tokenizer._special_tokens and pad_token not in special_tokens:special_tokens[pad_token] = idx16 unmodified linesclass CodeGen25Tokenizer(PreTrainedTokenizer):"""Construct a CodeGen2.5 tokenizer. Based on byte-level Byte-Pair-Encoding.Args:vocab_file (`str`):Path to the vocabulary file.11 unmodified lines):pad_token_added = AddedToken(pad_token, lstrip=False, rstrip=False) if isinstance(pad_token, str) else pad_tokeneos_token_added = AddedToken(eos_token, lstrip=False, rstrip=False) if isinstance(eos_token, str) else eos_tokensuper().__init__(pad_token=pad_token_added,eos_token=eos_token_added,1 unmodified lineadd_special_tokens=add_special_tokens,**kwargs,)self.add_eos_token = add_eos_tokenself.encoder = tiktoken_tokenizer(base="gpt2", pad_token=pad_token, add_special=add_special_tokens)@propertydef vocab_size(self):2 unmodified linesdef get_vocab(self):"""Returns vocab as a dict"""vocab = {self._convert_id_to_token(i): i for i in range(self.vocab_size)}return vocabdef _tokenize(self, text, **kwargs):85 unmodified lines# has no vocab filedef save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None):return ()3 unmodified lines4567891048 unmodified lines59606162636465666768697071727374757613 unmodified lines90919293949596979816 unmodified lines11511611711811912012111 unmodified lines1331341351361371381391401 unmodified line1421431441451461472 unmodified lines15015115215315415515685 unmodified lines2422432442453 unmodified lines# For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/Apache-2.0"""Tokenization classes for CodeGen2.5."""from typing import List, Optional, Unionfrom transformers.tokenization_utils import AddedToken, PreTrainedTokenizerfrom transformers.utils import logging48 unmodified lines]return fim_tokensdef include_additional_tokens():tokens = []tokens += [f"<dummy_{i}>" for i in range(4)]tokens.append("<sep>") # 50317tokens.append("<eom>") # 50318tokens += [f"<mask_{i}>" for i in reversed(range(1, 51199-50318+1))]return tokensadd_whitespaces = include_whitespace(n_min=2, n_max=32)add_tabs = include_tabs(n_min=2, n_max=10)fim_tokens = include_fim_tokens()additional_tokens = include_additional_tokens()tokenizer = tiktoken.get_encoding(base)13 unmodified linesfor sp in fim_tokens:special_tokens[sp] = idxidx += 1for sp in additional_tokens:special_tokens[sp] = idxidx += 1if pad_token and pad_token not in tokenizer._special_tokens and pad_token not in special_tokens:special_tokens[pad_token] = idx16 unmodified linesclass CodeGen25Tokenizer(PreTrainedTokenizer):"""Construct a CodeGen25 tokenizer. Based on byte-level Byte-Pair-Encoding.Args:vocab_file (`str`):Path to the vocabulary file.11 unmodified lines):pad_token_added = AddedToken(pad_token, lstrip=False, rstrip=False) if isinstance(pad_token, str) else pad_tokeneos_token_added = AddedToken(eos_token, lstrip=False, rstrip=False) if isinstance(eos_token, str) else eos_tokenself.add_eos_token = add_eos_tokenself.encoder = tiktoken_tokenizer(base="gpt2", pad_token=pad_token, add_special=add_special_tokens)super().__init__(pad_token=pad_token_added,eos_token=eos_token_added,1 unmodified lineadd_special_tokens=add_special_tokens,**kwargs,)@propertydef vocab_size(self):2 unmodified linesdef get_vocab(self):"""Returns vocab as a dict"""vocab = {self.encoder.decode_single_token_bytes(i): i for i in range(self.vocab_size)}return vocabdef _tokenize(self, text, **kwargs):85 unmodified lines# has no vocab filedef save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None):return ()
tokenization_codegen25.py+11-11