TheBloke commited on
Commit
8083324
1 Parent(s): 3dedbf1

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +437 -0
README.md ADDED
@@ -0,0 +1,437 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: beowolx/CodeNinja-1.0-OpenChat-7B
3
+ datasets:
4
+ - glaiveai/glaive-code-assistant-v2
5
+ - TokenBender/code_instructions_122k_alpaca_style
6
+ inference: false
7
+ language:
8
+ - en
9
+ license: mit
10
+ metrics:
11
+ - code_eval
12
+ model_creator: beowulf
13
+ model_name: CodeNinja 1.0 Openchat 7B
14
+ model_type: mistral
15
+ pipeline_tag: text-generation
16
+ prompt_template: 'GPT4 Correct User: {prompt}<|end_of_turn|>GPT4 Correct Assistant:
17
+
18
+ '
19
+ quantized_by: TheBloke
20
+ tags:
21
+ - code
22
+ - text-generation-inference
23
+ ---
24
+ <!-- markdownlint-disable MD041 -->
25
+
26
+ <!-- header start -->
27
+ <!-- 200823 -->
28
+ <div style="width: auto; margin-left: auto; margin-right: auto">
29
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
30
+ </div>
31
+ <div style="display: flex; justify-content: space-between; width: 100%;">
32
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
33
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
34
+ </div>
35
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
36
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://www.patreon.com/TheBlokeAI">Want to contribute? TheBloke's Patreon page</a></p>
37
+ </div>
38
+ </div>
39
+ <div style="text-align:center; margin-top: 0em; margin-bottom: 0em"><p style="margin-top: 0.25em; margin-bottom: 0em;">TheBloke's LLM work is generously supported by a grant from <a href="https://a16z.com">andreessen horowitz (a16z)</a></p></div>
40
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
41
+ <!-- header end -->
42
+
43
+ # CodeNinja 1.0 Openchat 7B - AWQ
44
+ - Model creator: [beowulf](https://huggingface.co/beowolx)
45
+ - Original model: [CodeNinja 1.0 Openchat 7B](https://huggingface.co/beowolx/CodeNinja-1.0-OpenChat-7B)
46
+
47
+ <!-- description start -->
48
+ ## Description
49
+
50
+ This repo contains AWQ model files for [beowulf's CodeNinja 1.0 Openchat 7B](https://huggingface.co/beowolx/CodeNinja-1.0-OpenChat-7B).
51
+
52
+ These files were quantised using hardware kindly provided by [Massed Compute](https://massedcompute.com/).
53
+
54
+
55
+ ### About AWQ
56
+
57
+ AWQ is an efficient, accurate and blazing-fast low-bit weight quantization method, currently supporting 4-bit quantization. Compared to GPTQ, it offers faster Transformers-based inference with equivalent or better quality compared to the most commonly used GPTQ settings.
58
+
59
+ AWQ models are currently supported on Linux and Windows, with NVidia GPUs only. macOS users: please use GGUF models instead.
60
+
61
+ It is supported by:
62
+
63
+ - [Text Generation Webui](https://github.com/oobabooga/text-generation-webui) - using Loader: AutoAWQ
64
+ - [vLLM](https://github.com/vllm-project/vllm) - version 0.2.2 or later for support for all model types.
65
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
66
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later, from any code or client that supports Transformers
67
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) - for use from Python code
68
+
69
+ <!-- description end -->
70
+ <!-- repositories-available start -->
71
+ ## Repositories available
72
+
73
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/CodeNinja-1.0-OpenChat-7B-AWQ)
74
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/CodeNinja-1.0-OpenChat-7B-GPTQ)
75
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/CodeNinja-1.0-OpenChat-7B-GGUF)
76
+ * [beowulf's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/beowolx/CodeNinja-1.0-OpenChat-7B)
77
+ <!-- repositories-available end -->
78
+
79
+ <!-- prompt-template start -->
80
+ ## Prompt template: OpenChat-Correct
81
+
82
+ ```
83
+ GPT4 Correct User: {prompt}<|end_of_turn|>GPT4 Correct Assistant:
84
+
85
+ ```
86
+
87
+ <!-- prompt-template end -->
88
+
89
+
90
+ <!-- README_AWQ.md-provided-files start -->
91
+ ## Provided files, and AWQ parameters
92
+
93
+ I currently release 128g GEMM models only. The addition of group_size 32 models, and GEMV kernel models, is being actively considered.
94
+
95
+ Models are released as sharded safetensors files.
96
+
97
+ | Branch | Bits | GS | AWQ Dataset | Seq Len | Size |
98
+ | ------ | ---- | -- | ----------- | ------- | ---- |
99
+ | [main](https://huggingface.co/TheBloke/CodeNinja-1.0-OpenChat-7B-AWQ/tree/main) | 4 | 128 | [Evol Instruct Code](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1/viewer/) | 4096 | 4.15 GB
100
+
101
+ <!-- README_AWQ.md-provided-files end -->
102
+
103
+ <!-- README_AWQ.md-text-generation-webui start -->
104
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
105
+
106
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
107
+
108
+ It is strongly recommended to use the text-generation-webui one-click-installers unless you're sure you know how to make a manual install.
109
+
110
+ 1. Click the **Model tab**.
111
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/CodeNinja-1.0-OpenChat-7B-AWQ`.
112
+ 3. Click **Download**.
113
+ 4. The model will start downloading. Once it's finished it will say "Done".
114
+ 5. In the top left, click the refresh icon next to **Model**.
115
+ 6. In the **Model** dropdown, choose the model you just downloaded: `CodeNinja-1.0-OpenChat-7B-AWQ`
116
+ 7. Select **Loader: AutoAWQ**.
117
+ 8. Click Load, and the model will load and is now ready for use.
118
+ 9. If you want any custom settings, set them and then click **Save settings for this model** followed by **Reload the Model** in the top right.
119
+ 10. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
120
+ <!-- README_AWQ.md-text-generation-webui end -->
121
+
122
+ <!-- README_AWQ.md-use-from-vllm start -->
123
+ ## Multi-user inference server: vLLM
124
+
125
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
126
+
127
+ - Please ensure you are using vLLM version 0.2 or later.
128
+ - When using vLLM as a server, pass the `--quantization awq` parameter.
129
+
130
+ For example:
131
+
132
+ ```shell
133
+ python3 -m vllm.entrypoints.api_server --model TheBloke/CodeNinja-1.0-OpenChat-7B-AWQ --quantization awq --dtype auto
134
+ ```
135
+
136
+ - When using vLLM from Python code, again set `quantization=awq`.
137
+
138
+ For example:
139
+
140
+ ```python
141
+ from vllm import LLM, SamplingParams
142
+
143
+ prompts = [
144
+ "Tell me about AI",
145
+ "Write a story about llamas",
146
+ "What is 291 - 150?",
147
+ "How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
148
+ ]
149
+ prompt_template=f'''GPT4 Correct User: {prompt}<|end_of_turn|>GPT4 Correct Assistant:
150
+ '''
151
+
152
+ prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
153
+
154
+ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
155
+
156
+ llm = LLM(model="TheBloke/CodeNinja-1.0-OpenChat-7B-AWQ", quantization="awq", dtype="auto")
157
+
158
+ outputs = llm.generate(prompts, sampling_params)
159
+
160
+ # Print the outputs.
161
+ for output in outputs:
162
+ prompt = output.prompt
163
+ generated_text = output.outputs[0].text
164
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
165
+ ```
166
+ <!-- README_AWQ.md-use-from-vllm start -->
167
+
168
+ <!-- README_AWQ.md-use-from-tgi start -->
169
+ ## Multi-user inference server: Hugging Face Text Generation Inference (TGI)
170
+
171
+ Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
172
+
173
+ Example Docker parameters:
174
+
175
+ ```shell
176
+ --model-id TheBloke/CodeNinja-1.0-OpenChat-7B-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
177
+ ```
178
+
179
+ Example Python code for interfacing with TGI (requires [huggingface-hub](https://github.com/huggingface/huggingface_hub) 0.17.0 or later):
180
+
181
+ ```shell
182
+ pip3 install huggingface-hub
183
+ ```
184
+
185
+ ```python
186
+ from huggingface_hub import InferenceClient
187
+
188
+ endpoint_url = "https://your-endpoint-url-here"
189
+
190
+ prompt = "Tell me about AI"
191
+ prompt_template=f'''GPT4 Correct User: {prompt}<|end_of_turn|>GPT4 Correct Assistant:
192
+ '''
193
+
194
+ client = InferenceClient(endpoint_url)
195
+ response = client.text_generation(prompt,
196
+ max_new_tokens=128,
197
+ do_sample=True,
198
+ temperature=0.7,
199
+ top_p=0.95,
200
+ top_k=40,
201
+ repetition_penalty=1.1)
202
+
203
+ print(f"Model output: ", response)
204
+ ```
205
+ <!-- README_AWQ.md-use-from-tgi end -->
206
+
207
+ <!-- README_AWQ.md-use-from-python start -->
208
+ ## Inference from Python code using Transformers
209
+
210
+ ### Install the necessary packages
211
+
212
+ - Requires: [Transformers](https://huggingface.co/docs/transformers) 4.35.0 or later.
213
+ - Requires: [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) 0.1.6 or later.
214
+
215
+ ```shell
216
+ pip3 install --upgrade "autoawq>=0.1.6" "transformers>=4.35.0"
217
+ ```
218
+
219
+ Note that if you are using PyTorch 2.0.1, the above AutoAWQ command will automatically upgrade you to PyTorch 2.1.0.
220
+
221
+ If you are using CUDA 11.8 and wish to continue using PyTorch 2.0.1, instead run this command:
222
+
223
+ ```shell
224
+ pip3 install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl
225
+ ```
226
+
227
+ If you have problems installing [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) using the pre-built wheels, install it from source instead:
228
+
229
+ ```shell
230
+ pip3 uninstall -y autoawq
231
+ git clone https://github.com/casper-hansen/AutoAWQ
232
+ cd AutoAWQ
233
+ pip3 install .
234
+ ```
235
+
236
+ ### Transformers example code (requires Transformers 4.35.0 and later)
237
+
238
+ ```python
239
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
240
+
241
+ model_name_or_path = "TheBloke/CodeNinja-1.0-OpenChat-7B-AWQ"
242
+
243
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
244
+ model = AutoModelForCausalLM.from_pretrained(
245
+ model_name_or_path,
246
+ low_cpu_mem_usage=True,
247
+ device_map="cuda:0"
248
+ )
249
+
250
+ # Using the text streamer to stream output one token at a time
251
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
252
+
253
+ prompt = "Tell me about AI"
254
+ prompt_template=f'''GPT4 Correct User: {prompt}<|end_of_turn|>GPT4 Correct Assistant:
255
+ '''
256
+
257
+ # Convert prompt to tokens
258
+ tokens = tokenizer(
259
+ prompt_template,
260
+ return_tensors='pt'
261
+ ).input_ids.cuda()
262
+
263
+ generation_params = {
264
+ "do_sample": True,
265
+ "temperature": 0.7,
266
+ "top_p": 0.95,
267
+ "top_k": 40,
268
+ "max_new_tokens": 512,
269
+ "repetition_penalty": 1.1
270
+ }
271
+
272
+ # Generate streamed output, visible one token at a time
273
+ generation_output = model.generate(
274
+ tokens,
275
+ streamer=streamer,
276
+ **generation_params
277
+ )
278
+
279
+ # Generation without a streamer, which will include the prompt in the output
280
+ generation_output = model.generate(
281
+ tokens,
282
+ **generation_params
283
+ )
284
+
285
+ # Get the tokens from the output, decode them, print them
286
+ token_output = generation_output[0]
287
+ text_output = tokenizer.decode(token_output)
288
+ print("model.generate output: ", text_output)
289
+
290
+ # Inference is also possible via Transformers' pipeline
291
+ from transformers import pipeline
292
+
293
+ pipe = pipeline(
294
+ "text-generation",
295
+ model=model,
296
+ tokenizer=tokenizer,
297
+ **generation_params
298
+ )
299
+
300
+ pipe_output = pipe(prompt_template)[0]['generated_text']
301
+ print("pipeline output: ", pipe_output)
302
+
303
+ ```
304
+ <!-- README_AWQ.md-use-from-python end -->
305
+
306
+ <!-- README_AWQ.md-compatibility start -->
307
+ ## Compatibility
308
+
309
+ The files provided are tested to work with:
310
+
311
+ - [text-generation-webui](https://github.com/oobabooga/text-generation-webui) using `Loader: AutoAWQ`.
312
+ - [vLLM](https://github.com/vllm-project/vllm) version 0.2.0 and later.
313
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) version 1.1.0 and later.
314
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later.
315
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) version 0.1.1 and later.
316
+
317
+ <!-- README_AWQ.md-compatibility end -->
318
+
319
+ <!-- footer start -->
320
+ <!-- 200823 -->
321
+ ## Discord
322
+
323
+ For further support, and discussions on these models and AI in general, join us at:
324
+
325
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
326
+
327
+ ## Thanks, and how to contribute
328
+
329
+ Thanks to the [chirper.ai](https://chirper.ai) team!
330
+
331
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
332
+
333
+ I've had a lot of people ask if they can contribute. I enjoy providing models and helping people, and would love to be able to spend even more time doing it, as well as expanding into new projects like fine tuning/training.
334
+
335
+ If you're able and willing to contribute it will be most gratefully received and will help me to keep providing more models, and to start work on new AI projects.
336
+
337
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
338
+
339
+ * Patreon: https://patreon.com/TheBlokeAI
340
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
341
+
342
+ **Special thanks to**: Aemon Algiz.
343
+
344
+ **Patreon special mentions**: Michael Levine, 阿明, Trailburnt, Nikolai Manek, John Detwiler, Randy H, Will Dee, Sebastain Graf, NimbleBox.ai, Eugene Pentland, Emad Mostaque, Ai Maven, Jim Angel, Jeff Scroggin, Michael Davis, Manuel Alberto Morcote, Stephen Murray, Robert, Justin Joy, Luke @flexchar, Brandon Frisco, Elijah Stavena, S_X, Dan Guido, Undi ., Komninos Chatzipapas, Shadi, theTransient, Lone Striker, Raven Klaugh, jjj, Cap'n Zoog, Michel-Marie MAUDET (LINAGORA), Matthew Berman, David, Fen Risland, Omer Bin Jawed, Luke Pendergrass, Kalila, OG, Erik Bjäreholt, Rooh Singh, Joseph William Delisle, Dan Lewis, TL, John Villwock, AzureBlack, Brad, Pedro Madruga, Caitlyn Gatomon, K, jinyuan sun, Mano Prime, Alex, Jeffrey Morgan, Alicia Loh, Illia Dulskyi, Chadd, transmissions 11, fincy, Rainer Wilmers, ReadyPlayerEmma, knownsqashed, Mandus, biorpg, Deo Leter, Brandon Phillips, SuperWojo, Sean Connelly, Iucharbius, Jack West, Harry Royden McLaughlin, Nicholas, terasurfer, Vitor Caleffi, Duane Dunston, Johann-Peter Hartmann, David Ziegler, Olakabola, Ken Nordquist, Trenton Dambrowitz, Tom X Nguyen, Vadim, Ajan Kanaga, Leonard Tan, Clay Pascal, Alexandros Triantafyllidis, JM33133, Xule, vamX, ya boyyy, subjectnull, Talal Aujan, Alps Aficionado, wassieverse, Ari Malik, James Bentley, Woland, Spencer Kim, Michael Dempsey, Fred von Graf, Elle, zynix, William Richards, Stanislav Ovsiannikov, Edmond Seymore, Jonathan Leane, Martin Kemka, usrbinkat, Enrico Ros
345
+
346
+
347
+ Thank you to all my generous patrons and donaters!
348
+
349
+ And thank you again to a16z for their generous grant.
350
+
351
+ <!-- footer end -->
352
+
353
+ # Original model card: beowulf's CodeNinja 1.0 Openchat 7B
354
+
355
+
356
+ <p align="center">
357
+ <img width="700px" alt="DeepSeek Coder" src="https://cdn-uploads.huggingface.co/production/uploads/64b566ab04fa6584c03b5247/5COagfF6EwrV4utZJ-ClI.png">
358
+ </p>
359
+ <hr>
360
+
361
+ # CodeNinja: Your Advanced Coding Assistant
362
+
363
+ ## Overview
364
+
365
+ CodeNinja is an enhanced version of the renowned model [openchat/openchat-3.5-1210](https://huggingface.co/openchat/openchat-3.5-1210). It represents a breakthrough in coding assistance, having been fine-tuned through Supervised Fine Tuning on two expansive datasets, encompassing over 400,000 coding instructions. Designed to be an indispensable tool for coders, CodeNinja aims to integrate seamlessly into your daily coding routine.
366
+
367
+ Discover the quantized versions at: [beowolx/CodeNinja-1.0-OpenChat-7B-GGUF](https://huggingface.co/beowolx/CodeNinja-1.0-OpenChat-7B-GGUF).
368
+
369
+ ### Key Features
370
+
371
+ - **Expansive Training Database**: CodeNinja has been refined with datasets from [glaiveai/glaive-code-assistant-v2](https://huggingface.co/datasets/glaiveai/glaive-code-assistant-v2) and [TokenBender/code_instructions_122k_alpaca_style](https://huggingface.co/datasets/TokenBender/code_instructions_122k_alpaca_style), incorporating around 400,000 coding instructions across various languages including Python, C, C++, Rust, Java, JavaScript, and more.
372
+
373
+ - **Flexibility and Scalability**: Available in a 7B model size, CodeNinja is adaptable for local runtime environments.
374
+
375
+ - **Exceptional Performance**: Achieves top-tier results among publicly accessible coding models, particularly notable on benchmarks like HumanEval.
376
+
377
+ - **Advanced Code Completion**: With a substantial context window size of 8192, it supports comprehensive project-level code completion.
378
+
379
+ ## Prompt Format
380
+
381
+ CodeNinja maintains the same prompt structure as OpenChat 3.5. Effective utilization requires adherence to this format:
382
+
383
+ ```
384
+ GPT4 Correct User: Hello<|end_of_turn|>GPT4 Correct Assistant: Hi<|end_of_turn|>GPT4 Correct User: How are you today?<|end_of_turn|>GPT4 Correct Assistant:
385
+ ```
386
+
387
+ 🚨 Important: Ensure the use of `<|end_of_turn|>` as the end-of-generation token.
388
+
389
+ **Adhering to this format is crucial for optimal results.**
390
+
391
+ ## Usage Instructions
392
+
393
+ ### Using LM Studio
394
+
395
+ The simplest way to engage with CodeNinja is via the [quantized versions](https://huggingface.co/beowolx/CodeNinja-1.0-OpenChat-7B-GGUF) on [LM Studio](https://lmstudio.ai/). Ensure you select the "OpenChat" preset, which incorporates the necessary prompt format. The preset is also available in this [gist](https://gist.github.com/beowolx/b219466681c02ff67baf8f313a3ad817).
396
+
397
+ ### Using the Transformers Library
398
+
399
+ ```python
400
+ from transformers import AutoTokenizer, AutoModelForCausalLM
401
+ import torch
402
+
403
+ # Initialize the model
404
+ model_path = "beowolx/CodeNinja-1.0-OpenChat-7B"
405
+ model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto")
406
+ # Load the OpenChat tokenizer
407
+ tokenizer = AutoTokenizer.from_pretrained("openchat/openchat-3.5-1210", use_fast=True)
408
+
409
+ def generate_one_completion(prompt: str):
410
+ messages = [
411
+ {"role": "user", "content": prompt},
412
+ {"role": "assistant", "content": ""} # Model response placeholder
413
+ ]
414
+
415
+ # Generate token IDs using the chat template
416
+ input_ids = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
417
+
418
+ # Produce completion
419
+ generate_ids = model.generate(
420
+ torch.tensor([input_ids]).to("cuda"),
421
+ max_length=256,
422
+ pad_token_id=tokenizer.pad_token_id,
423
+ eos_token_id=tokenizer.eos_token_id
424
+ )
425
+
426
+ # Process the completion
427
+ completion = tokenizer.decode(generate_ids[0], skip_special_tokens=True)
428
+ completion = completion.split("\n\n\n")[0].strip()
429
+
430
+ return completion
431
+ ```
432
+
433
+ ## License
434
+ CodeNinja is licensed under the MIT License, with model usage subject to the Model License.
435
+
436
+ ## Contact
437
+ For queries or support, please open an issue in the repository.