Zenos GPT-J 6B Instruct 4-bit
Model Overview
- Name: zenos-gpt-j-6B-instruct-4bit
- Datasets Used: Alpaca Spanish, Evol Instruct
- Architecture: GPT-J
- Model Size: 6 Billion parameters
- Precision: 4 bits
- Fine-tuning: This model was fine-tuned using Low-Rank Adaptation (LoRa).
- Content Moderation: This model is not moderated.
Description
Zenos GPT-J 6B Instruct 4-bit is a Spanish Instruction capable model based on the GPT-J architecture with 6 billion parameters. It has been fine-tuned on the Alpaca Spanish and Evol Instruct datasets, making it particularly suitable for natural language understanding and generation tasks in Spanish.
An experimental Twitter (
X) bot is available at
https://twitter.com/ZenosBot which makes comments on news published in media outlets from Argentina.
Requirements
The latest development version of Transformers, which includes serialization of 4 bits models.
- Transformers
- Bitsandbytes >= 0.41.3
Since this is a compressed version (4 bits), it can fit into ~7GB of VRAM.
Usage
You can use this model for various natural language processing tasks such as text generation, summarization, and more. Below is an example of how to use it in Python with the Transformers library:
1from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
2
3# Load the tokenizer and model
4tokenizer = AutoTokenizer.from_pretrained("webpolis/zenos-gpt-j-6B-instruct-4bit")
5model = AutoModelForCausalLM.from_pretrained(
6 "webpolis/zenos-gpt-j-6B-instruct-4bit",
7 use_safetensors=True
8)
9
10user_msg = '''Escribe un poema breve utilizando los siguientes conceptos:
11
12Bienestar, Corriente, Iluminación, Sed'''
13
14# Generate text; watch out the padding between [INST] ... [/INST]
15prompt = f'[INST] {user_msg} [/INST]'
16
17inputs = tokenizer(prompt, return_tensors="pt")
18input_ids = inputs["input_ids"].to(model.device)
19attention_mask = inputs["attention_mask"].to(model.device)
20
21generation_config = GenerationConfig(
22 temperature=0.2,
23 top_p=0.8,
24 top_k=40,
25 num_beams=1,
26 repetition_penalty=1.3,
27 do_sample=True
28)
29
30with torch.no_grad():
31 generation_output = model.generate(
32 input_ids=input_ids,
33 pad_token_id=tokenizer.eos_token_id,
34 attention_mask=attention_mask,
35 generation_config=generation_config,
36 return_dict_in_generate=True,
37 output_scores=False,
38 max_new_tokens=512,
39 early_stopping=True
40 )
41
42s = generation_output.sequences[0]
43output = tokenizer.decode(s)
44start_txt = output.find('[/INST]') + len('[/INST]')
45end_txt = output.find("<|endoftext|>", start_txt)
46answer = output[start_txt:end_txt]
47
48print(answer)
Inference
Online
Currently, the HuggingFace's Inference Tool UI doesn't properly load the model. However, you can use it with regular Python code as shown above once you meet the
requirements.
CPU
Best performance can be achieved downloading the
GGML 4 bits model and doing inference using the
rustformers' llm tool.
Requirements
For optimal performance:
In my Core i7 laptop it goes around 250ms per token:
Acknowledgments
This model was developed by
Nicolás Iglesias using the Hugging Face Transformers library.
LICENSE
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this software except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.