Instructions to use dorkai/codeX-1.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dorkai/codeX-1.0 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="dorkai/codeX-1.0")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("dorkai/codeX-1.0", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use dorkai/codeX-1.0 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "dorkai/codeX-1.0" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dorkai/codeX-1.0", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/dorkai/codeX-1.0
- SGLang
How to use dorkai/codeX-1.0 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 "dorkai/codeX-1.0" \ --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": "dorkai/codeX-1.0", "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 "dorkai/codeX-1.0" \ --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": "dorkai/codeX-1.0", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use dorkai/codeX-1.0 with Docker Model Runner:
docker model run hf.co/dorkai/codeX-1.0
| # Copyright (c) Microsoft Corporation. | |
| # Licensed under the MIT license. | |
| # https://github.com/microsoft/CodeXGLUE/tree/main/Code-Code/code-to-code-trans/evaluator/CodeBLEU | |
| # -*- coding:utf-8 -*- | |
| import argparse | |
| import os | |
| from evaluator.CodeBLEU import bleu, weighted_ngram_match, syntax_match, dataflow_match | |
| def get_codebleu(refs, hyp, lang, params='0.25,0.25,0.25,0.25'): | |
| if not isinstance(refs, list): | |
| refs = [refs] | |
| alpha, beta, gamma, theta = [float(x) for x in params.split(',')] | |
| # preprocess inputs | |
| pre_references = [[x.strip() for x in open(file, 'r', encoding='utf-8').readlines()] for file in refs] | |
| hypothesis = [x.strip() for x in open(hyp, 'r', encoding='utf-8').readlines()] | |
| for i in range(len(pre_references)): | |
| assert len(hypothesis) == len(pre_references[i]) | |
| references = [] | |
| for i in range(len(hypothesis)): | |
| ref_for_instance = [] | |
| for j in range(len(pre_references)): | |
| ref_for_instance.append(pre_references[j][i]) | |
| references.append(ref_for_instance) | |
| assert len(references) == len(pre_references) * len(hypothesis) | |
| # calculate ngram match (BLEU) | |
| tokenized_hyps = [x.split() for x in hypothesis] | |
| tokenized_refs = [[x.split() for x in reference] for reference in references] | |
| ngram_match_score = bleu.corpus_bleu(tokenized_refs, tokenized_hyps) | |
| # calculate weighted ngram match | |
| root_dir = os.path.dirname(__file__) | |
| keywords = [x.strip() for x in open(root_dir + '/keywords/' + lang + '.txt', 'r', encoding='utf-8').readlines()] | |
| def make_weights(reference_tokens, key_word_list): | |
| return {token: 1 if token in key_word_list else 0.2 for token in reference_tokens} | |
| tokenized_refs_with_weights = [[[reference_tokens, make_weights(reference_tokens, keywords)] \ | |
| for reference_tokens in reference] for reference in tokenized_refs] | |
| weighted_ngram_match_score = weighted_ngram_match.corpus_bleu(tokenized_refs_with_weights, tokenized_hyps) | |
| # calculate syntax match | |
| syntax_match_score = syntax_match.corpus_syntax_match(references, hypothesis, lang) | |
| # calculate dataflow match | |
| dataflow_match_score = dataflow_match.corpus_dataflow_match(references, hypothesis, lang) | |
| print('ngram match: {0}, weighted ngram match: {1}, syntax_match: {2}, dataflow_match: {3}'. \ | |
| format(ngram_match_score, weighted_ngram_match_score, syntax_match_score, dataflow_match_score)) | |
| code_bleu_score = alpha * ngram_match_score \ | |
| + beta * weighted_ngram_match_score \ | |
| + gamma * syntax_match_score \ | |
| + theta * dataflow_match_score | |
| return code_bleu_score | |
| if __name__ == '__main__': | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('--refs', type=str, nargs='+', required=True, | |
| help='reference files') | |
| parser.add_argument('--hyp', type=str, required=True, | |
| help='hypothesis file') | |
| parser.add_argument('--lang', type=str, required=True, | |
| choices=['java', 'js', 'c_sharp', 'php', 'go', 'python', 'ruby'], | |
| help='programming language') | |
| parser.add_argument('--params', type=str, default='0.25,0.25,0.25,0.25', | |
| help='alpha, beta and gamma') | |
| args = parser.parse_args() | |
| code_bleu_score = get_codebleu(args.refs, args.hyp, args.lang, args.params) | |
| print('CodeBLEU score: ', code_bleu_score) | |