Instructions to use semcoder/semcoder_s_1030 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use semcoder/semcoder_s_1030 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="semcoder/semcoder_s_1030") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("semcoder/semcoder_s_1030") model = AutoModelForCausalLM.from_pretrained("semcoder/semcoder_s_1030") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use semcoder/semcoder_s_1030 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "semcoder/semcoder_s_1030" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "semcoder/semcoder_s_1030", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/semcoder/semcoder_s_1030
- SGLang
How to use semcoder/semcoder_s_1030 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 "semcoder/semcoder_s_1030" \ --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": "semcoder/semcoder_s_1030", "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 "semcoder/semcoder_s_1030" \ --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": "semcoder/semcoder_s_1030", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use semcoder/semcoder_s_1030 with Docker Model Runner:
docker model run hf.co/semcoder/semcoder_s_1030
Robin Ding commited on
Commit ·
772665f
1
Parent(s): b6d8b1f
update README
Browse files
README.md
CHANGED
|
@@ -1,5 +1,81 @@
|
|
| 1 |
---
|
| 2 |
license: other
|
|
|
|
| 3 |
license_name: deepseek
|
| 4 |
license_link: https://github.com/deepseek-ai/DeepSeek-Coder/blob/main/LICENSE-MODEL
|
|
|
|
| 5 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: other
|
| 3 |
+
library_name: transformers
|
| 4 |
license_name: deepseek
|
| 5 |
license_link: https://github.com/deepseek-ai/DeepSeek-Coder/blob/main/LICENSE-MODEL
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
---
|
| 8 |
+
# 🤔 SemCoder: Training Code Language Models with Comprehensive Semantics Reasoning
|
| 9 |
+
|
| 10 |
+
> Refer to our GitHub repo [ARiSE-Lab/SemCoder](https://github.com/ARiSE-Lab/SemCoder/) for detailed introduction to SemCoder!
|
| 11 |
+
|
| 12 |
+
## Model Details
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
Use the code below to get started with the model. Make sure you installed the [transformers](https://huggingface.co/docs/transformers/index) library.
|
| 16 |
+
|
| 17 |
+
```python
|
| 18 |
+
from transformers import pipeline
|
| 19 |
+
import torch
|
| 20 |
+
|
| 21 |
+
generator = pipeline(
|
| 22 |
+
model="semcoder/semcoder_s_1030",
|
| 23 |
+
task="text-generation",
|
| 24 |
+
torch_dtype=torch.float16,
|
| 25 |
+
device_map="auto",
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Generate Code
|
| 29 |
+
|
| 30 |
+
CODEGEN_REQUEST = """You are an exceptionally intelligent coding assistant that consistently delivers accurate and reliable <Code> according to <NL_Description>
|
| 31 |
+
|
| 32 |
+
<NL_Description>
|
| 33 |
+
{desc}
|
| 34 |
+
|
| 35 |
+
<Code>
|
| 36 |
+
"""
|
| 37 |
+
desc = """You are tasked with implementing a Python class that simulates a simple version of a "To-Do List" application. The class should have the following functionalities:
|
| 38 |
+
1. Add a new task to the to-do list.
|
| 39 |
+
2. Mark a task as completed.
|
| 40 |
+
3. Display all tasks in the to-do list.
|
| 41 |
+
4. Display only the incomplete tasks in the to-do list.
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
prompt = CODEGEN_REQUEST.format(desc=desc)
|
| 45 |
+
result = generator(prompt, max_length=2048, num_return_sequences=1, temperature=0.0)
|
| 46 |
+
code = result[0]["generated_text"].split("```python")[1].split("```")[0]
|
| 47 |
+
print(code)
|
| 48 |
+
|
| 49 |
+
# Understand Code with Monologues
|
| 50 |
+
|
| 51 |
+
FWD_MNL_REQUEST = """Simulate the Execution: You are given a Python function and an assertion containing a function input. Complete the assertion containing the execution output corresponding to the given input in [ANSWER] and [/ANSWER] tags.
|
| 52 |
+
{code}
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
tests = """
|
| 56 |
+
todo_list = ToDoList()
|
| 57 |
+
todo_list.add_task("Buy groceries")
|
| 58 |
+
todo_list.add_task("Complete assignment")
|
| 59 |
+
todo_list.mark_completed("Buy groceries")
|
| 60 |
+
assert todo_list.tasks == ???
|
| 61 |
+
"""
|
| 62 |
+
code += tests
|
| 63 |
+
prompt = FWD_MNL_REQUEST.format(code=code)
|
| 64 |
+
result = generator(prompt, max_length=2048, num_return_sequences=1, temperature=0.0)
|
| 65 |
+
print(result[0]["generated_text"])
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
## Citation
|
| 69 |
+
|
| 70 |
+
```bibtex
|
| 71 |
+
@article{ding2024semcoder,
|
| 72 |
+
title={SemCoder: Training Code Language Models with Comprehensive Semantics},
|
| 73 |
+
author={Yangruibo Ding and Jinjun Peng and Marcus J. Min and Gail Kaiser and Junfeng Yang and Baishakhi Ray},
|
| 74 |
+
journal={arXiv preprint arXiv:2406.01006},
|
| 75 |
+
year={2024}
|
| 76 |
+
}
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
## Important Note
|
| 80 |
+
|
| 81 |
+
SemCoder models are trained on the synthetic data generated by OpenAI models. Please pay attention to OpenAI's [terms of use](https://openai.com/policies/terms-of-use) when using the models and the datasets. SemCoder will not compete with OpenAI's commercial products.
|