Update README.md
Browse files
README.md
CHANGED
@@ -47,4 +47,52 @@ The model was fine-tuned using the following datasets:
|
|
47 |
## Usage
|
48 |
To use the CodeMind model, you can access it through the Hugging Face model hub or by integrating it into your own applications using the provided API. Provide a coding problem or a question related to programming concepts, and the model will generate relevant explanations, code snippets, or guidance based on its training.
|
49 |
|
50 |
-
Please refer to the documentation and examples for detailed instructions on how to integrate and use the CodeMind model effectively.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
## Usage
|
48 |
To use the CodeMind model, you can access it through the Hugging Face model hub or by integrating it into your own applications using the provided API. Provide a coding problem or a question related to programming concepts, and the model will generate relevant explanations, code snippets, or guidance based on its training.
|
49 |
|
50 |
+
Please refer to the documentation and examples for detailed instructions on how to integrate and use the CodeMind model effectively.
|
51 |
+
|
52 |
+
Below we share some code snippets on how to get quickly started with running the model. After downloading the transformers library via 'pip install -U transformers', use the following snippet code.
|
53 |
+
|
54 |
+
#### Running the model on a CPU
|
55 |
+
|
56 |
+
```python
|
57 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
58 |
+
|
59 |
+
tokenizer = AutoTokenizer.from_pretrained("LimYeri/CodeMind-Gemma-7B-QLoRA-4bit")
|
60 |
+
model = AutoModelForCausalLM.from_pretrained("LimYeri/CodeMind-Gemma-7B-QLoRA-4bit")
|
61 |
+
|
62 |
+
input_text = "Tell me how to solve the Leetcode Two Sum problem"
|
63 |
+
input_ids = tokenizer(input_text, return_tensors="pt")
|
64 |
+
|
65 |
+
outputs = model.generate(**input_ids)
|
66 |
+
print(tokenizer.decode(outputs[0]))
|
67 |
+
```
|
68 |
+
|
69 |
+
|
70 |
+
#### Running the model on a single / multi GPU
|
71 |
+
|
72 |
+
```python
|
73 |
+
# pip install accelerate
|
74 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
75 |
+
|
76 |
+
tokenizer = AutoTokenizer.from_pretrained("LimYeri/CodeMind-Gemma-7B-QLoRA-4bit")
|
77 |
+
model = AutoModelForCausalLM.from_pretrained("LimYeri/CodeMind-Gemma-7B-QLoRA-4bit")
|
78 |
+
|
79 |
+
def get_completion(query: str, model, tokenizer) -> str:
|
80 |
+
device = "cuda:0"
|
81 |
+
prompt_template = """
|
82 |
+
<start_of_turn>user
|
83 |
+
Below is an instruction that describes a task. Write a response that appropriately completes the request.
|
84 |
+
{query}
|
85 |
+
<end_of_turn>\n\n<start_of_turn>model
|
86 |
+
|
87 |
+
"""
|
88 |
+
prompt = prompt_template.format(query=query)
|
89 |
+
encodeds = tokenizer(prompt, return_tensors="pt", add_special_tokens=True)
|
90 |
+
model_inputs = encodeds.to(device)
|
91 |
+
generated_ids = model.generate(**model_inputs, max_new_tokens=1000, do_sample=True, pad_token_id=tokenizer.eos_token_id)
|
92 |
+
# decoded = tokenizer.batch_decode(generated_ids)
|
93 |
+
decoded = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
94 |
+
return (decoded)
|
95 |
+
|
96 |
+
result = get_completion(query="Tell me how to solve the Leetcode Two Sum problem", model=model, tokenizer=tokenizer)
|
97 |
+
print(result)
|
98 |
+
```
|