Run this model with HF Jobs
Run OpenVINO/codegen25-7b-multi-fp16-ov on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/OpenVINO/codegen25-7b-multi-fp16-ov. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/OpenVINO/codegen25-7b-multi-fp16-ov on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/OpenVINO/codegen25-7b-multi-fp16-ov. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/OpenVINO/codegen25-7b-multi-fp16-ov. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use OpenVINO/codegen25-7b-multi-fp16-ov with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use OpenVINO/codegen25-7b-multi-fp16-ov with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="OpenVINO/codegen25-7b-multi-fp16-ov")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("OpenVINO/codegen25-7b-multi-fp16-ov") model = AutoModelForCausalLM.from_pretrained("OpenVINO/codegen25-7b-multi-fp16-ov", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use OpenVINO/codegen25-7b-multi-fp16-ov with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "OpenVINO/codegen25-7b-multi-fp16-ov" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "OpenVINO/codegen25-7b-multi-fp16-ov", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/OpenVINO/codegen25-7b-multi-fp16-ov
- SGLang
How to use OpenVINO/codegen25-7b-multi-fp16-ov 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 "OpenVINO/codegen25-7b-multi-fp16-ov" \ --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": "OpenVINO/codegen25-7b-multi-fp16-ov", "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 "OpenVINO/codegen25-7b-multi-fp16-ov" \ --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": "OpenVINO/codegen25-7b-multi-fp16-ov", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use OpenVINO/codegen25-7b-multi-fp16-ov with Docker Model Runner:
docker model run hf.co/OpenVINO/codegen25-7b-multi-fp16-ov
Upload 8 files
Browse filesFiles changed (8)
- README.mdAdded+62
- config.jsonAdded+28
- generation_config.jsonAdded+6
- openvino_model.binAdded+3
- openvino_model.xmlAdded
- special_tokens_map.jsonAdded+9
- tokenization_codegen25.pyAdded+248
- tokenizer_config.jsonAdded+24
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162---license: apache-2.0language:- en---
# codegen25-7b-multi
* Model creator: [Salesforce](https://huggingface.co/Salesforce) * Original model: [CodeGen2.5-7B-multi](https://huggingface.co/Salesforce/codegen25-7b-multi_P)
## Description
This is [CodeGen2.5-7B-multi](https://huggingface.co/Salesforce/codegen25-7b-multi_P) model converted to the [OpenVINO™ IR](https://docs.openvino.ai/2024/documentation/openvino-ir-format.html) (Intermediate Representation) format with weights compressed to INT8 by [NNCF](https://github.com/openvinotoolkit/nncf).
## Quantization Parameters
Weight compression was performed using `nncf.compress_weights` with the following parameters:
* mode: **INT8_ASYM**
For more information on quantization, check the [OpenVINO model optimization guide](https://docs.openvino.ai/2024/openvino-workflow/model-optimization-guide/weight-compression.html).
## Compatibility
The provided OpenVINO™ IR model is compatible with:
* OpenVINO version 2024.1.0 and higher* Optimum Intel 1.16.0 and higher
## Running Model Inference
1. Install packages required for using [Optimum Intel](https://huggingface.co/docs/optimum/intel/index) integration with the OpenVINO backend:
```pip install optimum[openvino] tiktoken```
2. Run model inference:
```from transformers import AutoTokenizerfrom optimum.intel.openvino import OVModelForCausalLM
model_id = "OpenVINO/codegen25-7b-multi-int8-ov"tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)model = OVModelForCausalLM.from_pretrained(model_id)text = "def hello_world():"input_ids = tokenizer(text, return_tensors="pt").input_idsgenerated_ids = model.generate(input_ids, max_length=128)print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))```
For more examples and possible optimizations, refer to the [OpenVINO Large Language Model Inference Guide](https://docs.openvino.ai/2024/learn-openvino/llm_inference_guide.html).
## Limitations
Check the original model card for [limitations](https://huggingface.co/Salesforce/codegen25-7b-instruct_P#intended-use-and-limitations).
## Legal information
The original model is distributed under [Apache 2.0](https://choosealicense.com/licenses/apache-2.0/) license. More details can be found in [original model card](https://huggingface.co/Salesforce/codegen25-7b-multi_P).12345678910111213141516171819202122232425262728{ "_name_or_path": "Salesforce/codegen25-7b-multi_P", "architectures": [ "LlamaForCausalLM" ], "attention_bias": false, "attention_dropout": 0.0, "bos_token_id": 50256, "eos_token_id": 50256, "hidden_act": "silu", "hidden_size": 4096, "initializer_range": 0.02, "intermediate_size": 11008, "max_position_embeddings": 2048, "model_type": "llama", "num_attention_heads": 32, "num_hidden_layers": 32, "num_key_value_heads": 32, "pad_token_id": 0, "pretraining_tp": 1, "rms_norm_eps": 1e-06, "rope_scaling": null, "rope_theta": 10000.0, "tie_word_embeddings": false, "transformers_version": "4.40.1", "use_cache": true, "vocab_size": 51200}123456{ "_from_model_config": true, "bos_token_id": 50256, "eos_token_id": 50256, "transformers_version": "4.40.1"}123version https://git-lfs.github.com/spec/v1oid sha256:2abe360659e1333ee313628f51c006c3ee733dbda1324bcdad4736f1fe722195size 13791404424123456789{ "eos_token": { "content": "<|endoftext|>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248# Copyright (c) 2023, salesforce.com, inc.# All rights reserved.# SPDX-License-Identifier: Apache-2.0# 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
from transformers.tokenization_utils import AddedToken, PreTrainedTokenizerfrom transformers.utils import logging
try: import tiktokenexcept ModuleNotFoundError as e: raise ModuleNotFoundError("CodeGen2.5 requires the installation of tiktoken. Please install it via `pip install tiktoken`.") from e
logger = logging.get_logger(__name__)
MAX_MODEL_INPUT_SIZES = { "Salesforce/codegen25-7b-multi": 2048, "Salesforce/codegen25-7b-mono": 2048, "Salesforce/codegen25-7b-instruct": 2048,}
def tiktoken_tokenizer(base="gpt2", pad_token=None, add_special=True): if not add_special: return tiktoken.get_encoding(base)
def include_whitespace(n_min=2, n_max=20): whitespaces = [" " * n for n in reversed(range(n_min, n_max))] return whitespaces
def include_tabs(n_min=2, n_max=20): tabs = ["\t" * n for n in reversed(range(n_min, n_max))] return tabs
def include_fim_tokens(): fim_tokens = [ "<fim_prefix>", "<fim_middle>", "<fim_suffix>", "<fim_pad>", "<filename>", "<gh_stars>", "<issue_start>", "<issue_comment>", "<issue_closed>", "<jupyter_start>", "<jupyter_text>", "<jupyter_code>", "<jupyter_output>", "<empty_output>", "<commit_before>", "<commit_msg>", "<commit_after>", "<reponame>" ] return fim_tokens
def include_codegen2_tokens(): tokens = [] tokens += [f"<dummy_{i}>" for i in range(4)] tokens.append("<sep>") # 50317 tokens.append("<eom>") # 50318 tokens += [f"<mask_{i}>" for i in reversed(range(1, 51199-50318+1))] return tokens
add_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)
idx = tokenizer.n_vocab
bpe_ranks = tokenizer._mergeable_ranks
for wsp in add_whitespaces: bpe_ranks[bytes(wsp, 'ascii')] = idx idx += 1 for t in add_tabs: bpe_ranks[bytes(t, 'ascii')] = idx idx += 1
special_tokens = dict()
for sp in fim_tokens: special_tokens[sp] = idx idx += 1 for sp in codegen2_tokens: special_tokens[sp] = idx idx += 1
if pad_token and pad_token not in tokenizer._special_tokens and pad_token not in special_tokens: special_tokens[pad_token] = idx idx += 1 # In production, load the arguments directly instead of accessing private attributes # See openai_public.py for examples of arguments for specific encodings enc = tiktoken.Encoding( # If you're changing the set of special tokens, make sure to use a different name # It should be clear from the name what behaviour to expect. name=base.replace("base", "im"), pat_str=tokenizer._pat_str, mergeable_ranks=bpe_ranks, special_tokens={ **tokenizer._special_tokens, **special_tokens } ) return enc
class CodeGen25Tokenizer(PreTrainedTokenizer): """ Construct a CodeGen2.5 tokenizer. Based on byte-level Byte-Pair-Encoding. Args: vocab_file (`str`): Path to the vocabulary file. """ max_model_input_sizes = MAX_MODEL_INPUT_SIZES model_input_names = ["input_ids", "attention_mask"]
def __init__( self, pad_token=None, eos_token="<|endoftext|>", add_eos_token=False, add_special_tokens=True, **kwargs, ): pad_token_added = AddedToken(pad_token, lstrip=False, rstrip=False) if isinstance(pad_token, str) else pad_token eos_token_added = AddedToken(eos_token, lstrip=False, rstrip=False) if isinstance(eos_token, str) else eos_token self.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, add_eos_token=add_eos_token, **kwargs, ) self.add_eos_token = add_eos_token
@property def vocab_size(self): """Returns vocab size""" return self.encoder.n_vocab
def get_vocab(self): """Returns vocab as a dict""" vocab = {self._convert_id_to_token(i): i for i in range(self.vocab_size)} return vocab
def _tokenize(self, text, **kwargs): """Returns a tokenized string.""" return self.encoder.encode(text, allowed_special="all")
def _convert_token_to_id(self, token): """Converts a token (str) in an id using the vocab.""" if isinstance(token, str): return self.encoder.encode_single_token(token) else: return token
def _convert_id_to_token(self, index): """Converts an index (integer) in a token (str) using the vocab.""" try: token = self.encoder.decode_single_token_bytes(index).decode("utf-8") except Exception: token = "" return token
def _decode(self, token_ids: List[int], skip_special_tokens: bool = False, **kwargs): if skip_special_tokens: token_ids = [t for t in token_ids if t not in self.all_special_ids] return self.encoder.decode(token_ids)
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None) -> List[int]: """Build model inputs from a sequence by appending eos_token_id.""" eos_token_id = [self.eos_token_id] if self.add_eos_token else []
output = token_ids_0 + eos_token_id
if token_ids_1 is not None: output = output + token_ids_1 + eos_token_id
return output
def get_special_tokens_mask( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False ) -> List[int]: """ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding special tokens using the tokenizer `prepare_for_model` method. Args: token_ids_0 (`List[int]`): List of IDs. token_ids_1 (`List[int]`, *optional*): Optional second list of IDs for sequence pairs. already_has_special_tokens (`bool`, *optional*, defaults to `False`): Whether the token list is already formatted with special tokens for the model. Returns: `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token. """ if already_has_special_tokens: return super().get_special_tokens_mask( token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True )
eos_token_id = [1] if self.add_eos_token else []
if token_ids_1 is None: return ([0] * len(token_ids_0)) + eos_token_id return ([0] * len(token_ids_0)) + eos_token_id + ([0] * len(token_ids_1)) + eos_token_id
def create_token_type_ids_from_sequences( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Creates a mask from the two sequences passed to be used in a sequence-pair classification task. An ALBERT sequence pair mask has the following format: ``` 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 | first sequence | second sequence | ``` if token_ids_1 is None, only returns the first portion of the mask (0s). Args: token_ids_0 (`List[int]`): List of ids. token_ids_1 (`List[int]`, *optional*): Optional second list of IDs for sequence pairs. Returns: `List[int]`: List of [token type IDs](../glossary#token-type-ids) according to the given sequence(s). """ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
output = [0] * len(token_ids_0 + eos_token_id)
if token_ids_1 is not None: output += [1] * len(token_ids_1 + eos_token_id)
return output
# has no vocab file def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None): return ()123456789101112131415161718192021222324{ "add_eos_token": false, "added_tokens_decoder": { "50256": { "content": "<|endoftext|>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true } }, "auto_map": { "AutoTokenizer": [ "tokenization_codegen25.CodeGen25Tokenizer", null ] }, "clean_up_tokenization_spaces": true, "eos_token": "<|endoftext|>", "model_max_length": 2048, "pad_token": null, "tokenizer_class": "CodeGen25Tokenizer"}README.mdAdded+62
config.jsonAdded+28
generation_config.jsonAdded+6
openvino_model.binAdded+3
openvino_model.xmlAdded
special_tokens_map.jsonAdded+9
tokenization_codegen25.pyAdded+248
tokenizer_config.jsonAdded+24