Gemma is a family of lightweight, state-of-the-art open models from Google, built from the same research and technology used to create the Gemini models. They are text-to-text, decoder-only large language models, available in English, with open weights, pre-trained variants, and instruction-tuned variants. Gemma models are well-suited for a variety of text generation tasks, including question answering, summarization, and reasoning. Their relatively small size makes it possible to deploy them in environments with limited resources such as a laptop, desktop or your own cloud infrastructure, democratizing access to state of the art AI models and helping foster innovation for everyone.
CodeAlpaca_20K: contains 20K instruction-following data used for fine-tuning the Code Alpaca model.
Training took 1h 40 min on Free Colab T4 GPU (16GB VRAM) with the following params:
1num_train_epochs=2,
2per_device_train_batch_size=2,
3per_device_eval_batch_size=1,
4gradient_accumulation_steps=32
5learning_rate=2.5e-5,
6optim="paged_adamw_8bit",
7logging_steps=5,
8seed=66,
9load_best_model_at_end=True,
10save_strategy="steps",
11save_steps=50,
12evaluation_strategy="steps",
13eval_steps=50,
14save_total_limit=2,
15remove_unused_columns=True,
16fp16=True,
17bf16=False
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
3
4model_id = "MAISAAI/gemma-2b-coder"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7
8model = AutoModelForCausalLM.from_pretrained(model_id).to("cuda")
9
10def generate(
11 instruction,
12 max_new_tokens=256,
13 temperature=0.1,
14 top_p=0.75,
15 top_k=40,
16 num_beams=2,
17 **kwargs,
18):
19 system = f"<bos><|system|>\nYou are a helpful coding assistant.<eos>\n"
20 prompt = f"{system}<|user|>\n{instruction}<eos>\n<|assistant|>\n"
21 inputs = tokenizer(prompt, return_tensors="pt")
22 input_ids = inputs["input_ids"].to("cuda")
23 attention_mask = inputs["attention_mask"].to("cuda")
24 generation_config = GenerationConfig(
25 temperature=temperature,
26 top_p=top_p,
27 top_k=top_k,
28 num_beams=num_beams,
29 **kwargs,
30 )
31 with torch.no_grad():
32 generation_output = model.generate(
33 input_ids=input_ids,
34 attention_mask=attention_mask,
35 generation_config=generation_config,
36 return_dict_in_generate=True,
37 max_new_tokens=max_new_tokens,
38 early_stopping=True
39 )
40 s = generation_output.sequences[0]
41 output = tokenizer.decode(s, skip_special_tokens=True)
42 return output.split("<|assistant|>")[1]
43
44instruction = """
45Edit the following XML code to add a navigation bar to the top of a web page
46<html>
47<head>
48 <title>Maisa</title>
49</head>
50"""
51print(generate(instruction))
1@misc {maisa_ai_2024,
2 author = { {MAISA AI} },
3 title = { gemma-2b-coder (Revision e5e4e5b) },
4 year = 2024,
5 url = { https://huggingface.co/MAISAAI/gemma-2b-coder },
6 doi = { 10.57967/hf/2208 },
7 publisher = { Hugging Face }
8}