Instructions to use elsagranger/VirtualCompiler with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use elsagranger/VirtualCompiler with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="elsagranger/VirtualCompiler")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("elsagranger/VirtualCompiler") model = AutoModelForCausalLM.from_pretrained("elsagranger/VirtualCompiler", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use elsagranger/VirtualCompiler with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "elsagranger/VirtualCompiler" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "elsagranger/VirtualCompiler", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/elsagranger/VirtualCompiler
- SGLang
How to use elsagranger/VirtualCompiler 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 "elsagranger/VirtualCompiler" \ --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": "elsagranger/VirtualCompiler", "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 "elsagranger/VirtualCompiler" \ --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": "elsagranger/VirtualCompiler", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use elsagranger/VirtualCompiler with Docker Model Runner:
docker model run hf.co/elsagranger/VirtualCompiler
File size: 1,338 Bytes
78bb3c5 | 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 | import requests
import random
CL = ['clang-11', 'clang-12', 'clang-9', 'gcc-11', 'gcc-7', 'gcc-9']
OP = ['O0', 'O1', 'O2', 'O3', 'Os']
ST = ['stripped', 'unstripped']
def process(source_code):
compiler = random.choice(CL)
optimizer = random.choice(OP)
strip_type = random.choice(ST)
prompt = f'Please compile this source code using {compiler} with optimization level {optimizer} into assembly code.'
if strip_type == 'stripped':
prompt += ' Strip the assembly code.'
else:
prompt += ' No strip the assembly code.'
query_prompt = "<s>system\n" + prompt + \
"</s>\n<s>user\n" + source_code + "</s>\n<s>assistant\n"
return query_prompt, compiler, optimizer, strip_type
def do_request(src):
url = "http://localhost:8080/v1/completions"
query_prompt, _, _, _ = process(src)
model_name = "VirtualCompiler"
ret = requests.post(url, json={
"prompt": query_prompt,
"max_tokens": 4096,
"temperature": 0.3,
"stop": ["</s>"],
"model": model_name,
"echo": False,
"logprobs": True,
})
return ret.json()
src = '''static int
layout_append(struct layout_cell *lc, char *buf, size_t len)
{
if (len == 0)
return (-1);
return (0);
}
'''
ret = do_request(src)
print(ret['choices'][0]['text'])
|