Text Generation
Transformers
Safetensors
English
CoDA
feature-extraction
text diffusion model
language model
code generation
conversational
custom_code
Instructions to use Salesforce/CoDA-v0-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Salesforce/CoDA-v0-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Salesforce/CoDA-v0-Base", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Salesforce/CoDA-v0-Base", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Salesforce/CoDA-v0-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Salesforce/CoDA-v0-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Salesforce/CoDA-v0-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Salesforce/CoDA-v0-Base
- SGLang
How to use Salesforce/CoDA-v0-Base 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/CoDA-v0-Base" \ --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": "Salesforce/CoDA-v0-Base", "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 "Salesforce/CoDA-v0-Base" \ --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": "Salesforce/CoDA-v0-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Salesforce/CoDA-v0-Base with Docker Model Runner:
docker model run hf.co/Salesforce/CoDA-v0-Base
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,82 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: cc-by-nc-4.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- diffusion
|
| 8 |
+
- text generation
|
| 9 |
+
- code generation
|
| 10 |
+
---
|
| 11 |
+
# CoDA-v0-Base
|
| 12 |
+
|
| 13 |
+
## Overview
|
| 14 |
+
CoDA is Salesforce AI Research's open, lightweight and diffusion-based language model.
|
| 15 |
+
|
| 16 |
+
[Technical Report (Coming soon)]()
|
| 17 |
+
|
| 18 |
+
[Code](https://github.com/SalesforceAIResearch/CoDA/)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
## Requirements
|
| 23 |
+
```
|
| 24 |
+
torch==2.8.0
|
| 25 |
+
transformers>=4.47.1
|
| 26 |
+
flash-attn==2.8.3
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
## Quickstart
|
| 30 |
+
Here is a code snippet for loading the model, tokenizer and run unmasking for a partially finished code.
|
| 31 |
+
```python
|
| 32 |
+
import torch
|
| 33 |
+
from transformers import AutoModel, AutoTokenizer
|
| 34 |
+
|
| 35 |
+
model_name = "Salesforce/CoDA-v0-Base"
|
| 36 |
+
device = "cuda"
|
| 37 |
+
|
| 38 |
+
model = AutoModel.from_pretrained(model_name, torch_dtype=torch.bfloat16, trust_remote_code=True).to(device)
|
| 39 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 40 |
+
model.eval()
|
| 41 |
+
|
| 42 |
+
prompt = """```python
|
| 43 |
+
from typing import List
|
| 44 |
+
|
| 45 |
+
class Solution:
|
| 46 |
+
def twoSum(self, nums: List[int], target: int) -> List[int]:
|
| 47 |
+
# Create a dictionary to store the numbers and their indices
|
| 48 |
+
num_to_index = {}
|
| 49 |
+
|
| 50 |
+
# Iterate over the list of numbers
|
| 51 |
+
for index, num in enumerate(nums):
|
| 52 |
+
# Calculate the complement
|
| 53 |
+
complement = target - num
|
| 54 |
+
|
| 55 |
+
# Check if the complement is already in the dictionary
|
| 56 |
+
if complement in num_to_index:
|
| 57 |
+
# If found, return the indices of the complement and the current number
|
| 58 |
+
return [num_to_index[complement], index]
|
| 59 |
+
|
| 60 |
+
# Otherwise, add the current number and its index to the dictionary
|
| 61 |
+
num_to_index[num] = index
|
| 62 |
+
```"""
|
| 63 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
| 64 |
+
mask = torch.rand(input_ids.shape) < 0.4
|
| 65 |
+
masked_input_ids = input_ids.clone()
|
| 66 |
+
masked_input_ids[mask] = tokenizer.mask_token_id
|
| 67 |
+
generated_ids = model.diffusion_generate(
|
| 68 |
+
inputs=masked_input_ids.to(model.device),
|
| 69 |
+
max_new_tokens=1,
|
| 70 |
+
steps=128,
|
| 71 |
+
top_p=0.95,
|
| 72 |
+
temperature=0.2,
|
| 73 |
+
alg="entropy",
|
| 74 |
+
alg_temp=0.2,
|
| 75 |
+
)
|
| 76 |
+
generated_ids = [
|
| 77 |
+
output_ids[:-1] for output_ids in generated_ids
|
| 78 |
+
]
|
| 79 |
+
unmasked_output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
```
|