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 |
+
```
|