Text Generation
Transformers
PyTorch
English
gpt_neox
code
knowledge extraction
tiny
small
C
text-generation-inference
Instructions to use Mxode/Pythia-70m-C-Language-KnowledgeExtract with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Mxode/Pythia-70m-C-Language-KnowledgeExtract with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Mxode/Pythia-70m-C-Language-KnowledgeExtract")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Mxode/Pythia-70m-C-Language-KnowledgeExtract") model = AutoModelForCausalLM.from_pretrained("Mxode/Pythia-70m-C-Language-KnowledgeExtract") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Mxode/Pythia-70m-C-Language-KnowledgeExtract with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Mxode/Pythia-70m-C-Language-KnowledgeExtract" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Mxode/Pythia-70m-C-Language-KnowledgeExtract", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Mxode/Pythia-70m-C-Language-KnowledgeExtract
- SGLang
How to use Mxode/Pythia-70m-C-Language-KnowledgeExtract 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 "Mxode/Pythia-70m-C-Language-KnowledgeExtract" \ --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": "Mxode/Pythia-70m-C-Language-KnowledgeExtract", "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 "Mxode/Pythia-70m-C-Language-KnowledgeExtract" \ --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": "Mxode/Pythia-70m-C-Language-KnowledgeExtract", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Mxode/Pythia-70m-C-Language-KnowledgeExtract with Docker Model Runner:
docker model run hf.co/Mxode/Pythia-70m-C-Language-KnowledgeExtract
File size: 2,801 Bytes
a6bb176 e77286d 139a5db a6bb176 139a5db ad7a79a e77286d 139a5db e77286d a4d4ad6 e77286d 71fb641 e77286d 139a5db e77286d a4d4ad6 e77286d a4d4ad6 139a5db e77286d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | ---
license: apache-2.0
language:
- en
tags:
- code
- knowledge extraction
- tiny
- small
- C
---
## Model info
A model that can **extract the knowledge points** from the given **C language code**.
The base model is [pythia-70m](https://huggingface.co/EleutherAI/pythia-70m). This model was fine-tuned with 10 epochs using [Q-Lora](https://github.com/artidoro/qlora) method on my own training set.
## How to use
### quick start
A usage example is as follows, first import the model and prepare the code:
```python
from transformers import GPTNeoXForCausalLM, AutoTokenizer
model_name_or_path = 'Mxode/Pythia-70m-C-Language-KnowledgeExtract'
device = 'cuda'
model = GPTNeoXForCausalLM.from_pretrained(model_name_or_path).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
# instruction template
instruction = '[Summarize the knowledge points in the code below]\n'
# any c-lang pieces you like, could be partial functions or statements
input_content = '''```c
int partition(int arr[], int low, int high) {
int pivot = arr[high];
int i = (low - 1);
for (int j = low; j <= high - 1; j++) {
if (arr[j] < pivot) {
i++;
swap(&arr[i], &arr[j]);
}
}
swap(&arr[i + 1], &arr[high]);
return (i + 1);
}
void quickSort(int arr[], int low, int high) {
if (low < high) {
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
```'''
text = instruction + input_content
```
Then generate:
```python
inputs = tokenizer(text, return_tensors="pt").to(device)
tokens = model.generate(
**inputs,
pad_token_id=tokenizer.eos_token_id,
max_new_tokens=32,
)
# deduplicate inputs
response = tokenizer.decode(tokens[0]).split('```')[-1].split('<')[0]
```
### and more
However, in practical use, in order to achieve more diverse representations, it's recommended to do multiple inferences. Don't worry, it's really small so the inferences don't take much time, as follows:
```python
ans_dict = {}
def increment_insert(key):
ans_dict[key] = ans_dict.get(key, 0) + 1
for i in range(30): # maybe 20 times or less enough too
inputs = tokenizer(text, return_tensors="pt").to(device)
tokens = model.generate(
**inputs,
pad_token_id=tokenizer.eos_token_id,
max_new_tokens=32,
do_sample=True,
temperature=2.0, # high temperature for diversity
top_p=0.95,
top_k=30,
)
response = tokenizer.decode(tokens[0]).split('```')[-1].split('<')[0]
increment_insert(response)
print(ans_dict)
### output as below, could take high-freq answers
### {
### 'Backtracking': 1,
### 'Heap': 1,
### 'Quick sort': 25,
### 'Recurrence': 2,
### 'Queue': 1
### }
``` |