Instructions to use EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2") model = AutoModelForCausalLM.from_pretrained("EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2
- SGLang
How to use EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2 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 "EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2 to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2", max_seq_length=2048, ) - Docker Model Runner
How to use EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2 with Docker Model Runner:
docker model run hf.co/EpistemeAI2/Athene-codegemma-2-7b-it-alpaca-v1.2
Model Information
Summary description and brief definition of inputs and outputs.
Description
Athene CodeGemma 2 7B v1.2 is a collection of lightweight open code models built on top of Gemma. CodeGemma models are text-to-text and text-to-code decoder-only models and are available as a 7 billion pretrained variant that specializes in code completion and code generation tasks, a 7 billion parameter instruction-tuned variant for code chat and instruction following and a 2 billion parameter pretrained variant for fast code completion. Supervised Fine-tuning with coding datasets.
similar to:
| codegemma-2b | codegemma-7b | codegemma-7b-it | |
|---|---|---|---|
| Code Completion | ✅ | ✅ | |
| Generation from natural language | ✅ | ✅ | |
| Chat | ✅ | ||
| Instruction Following | ✅ |
Sample Usage
This model is intended to answer questions about code fragments, to generate code from natural language, or to engage in a conversation with the user about programming or technical problems. If you need to use code completion (for example, integrated in an IDE), we recommend you use one of the pre-trained models instead: CodeGemma 7B, or CodeGemma 2B.
For Code Generation
from transformers import GemmaTokenizer, AutoModelForCausalLM
tokenizer = GemmaTokenizer.from_pretrained("EpistemeAI/Athene-codegemma-2-7b-it-alpaca-v1.2")
model = AutoModelForCausalLM.from_pretrained("EpistemeAI/Athene-codegemma-2-7b-it-alpaca-v1.2")
input_text = "Write me a Python function to calculate the nth fibonacci number."
input_ids = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))
Chat Template
The instruction-tuned models use a chat template that must be adhered to for conversational use. The easiest way to apply it is using the tokenizer's built-in chat template, as shown in the following snippet.
Let's load the model and apply the chat template to a conversation. In this example, we'll start with a single user interaction:
from transformers import AutoTokenizer, AutoModelForCausalLM
import transformers
import torch
model_id = "EpistemeAI/Athene-codegemma-2-7b-it-alpaca-v1.2"
dtype = torch.bfloat16
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="cuda",
torch_dtype=dtype,
)
chat = [
{ "role": "user", "content": "Write a hello world program" },
]
prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
At this point, the prompt contains the following text:
<bos><start_of_turn>user
Write a hello world program<end_of_turn>
<start_of_turn>model
As you can see, each turn is preceded by a <start_of_turn> delimiter and then the role of the entity
(either user, for content supplied by the user, or model for LLM responses). Turns finish with
the <end_of_turn> token.
You can follow this format to build the prompt manually, if you need to do it without the tokenizer's chat template.
After the prompt is ready, generation can be performed like this:
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=150)
Inputs and Outputs
Inputs : For pretrained model variants: code prefix and/or suffix for code completion and generation scenarios, or natural language text or prompt : For instruction tuned model variant: natural language text or prompt
Outputs : For pretrained model variants: fill-in-the-middle code completion, code and natural language : For instruction tuned model variant: code and natural language
Model Data
Data used for model training and how the data was processed.
Training Dataset
Supervised Fine-tuning with coding python, java datasets
Example: Athene CodeGemma 2 7B v1.2
Athene CodeGemma 2 7B v1.1 successfully created snake game without errors compare to original codegemma-7b-it
import pygame
import sys
import time
import random
# Initialize Pygame
pygame.init()
# Set up some constants
WIDTH = 800
HEIGHT = 600
BLOCK_SIZE = 20
# Create the game screen
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# Set up the colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
# Set up the font
font = pygame.font.Font(None, 36)
# Set up the snake and food
snake = [(200, 200), (220, 200), (240, 200)]
food = (400, 300)
# Set up the direction
direction = 'RIGHT'
# Game loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP and direction!= 'DOWN':
direction = 'UP'
elif event.key == pygame.K_DOWN and direction!= 'UP':
direction = 'DOWN'
elif event.key == pygame.K_LEFT and direction!= 'RIGHT':
direction = 'LEFT'
elif event.key == pygame.K_RIGHT and direction!= 'LEFT':
direction = 'RIGHT'
# Move the snake
head = snake[-1]
if direction == 'UP':
new_head = (head[0], head[1] - BLOCK_SIZE)
elif direction == 'DOWN':
new_head = (head[0], head[1] + BLOCK_SIZE)
elif direction == 'LEFT':
new_head = (head[0] - BLOCK_SIZE, head[1])
elif direction == 'RIGHT':
new_head = (head[0] + BLOCK_SIZE, head[1])
snake.append(new_head)
# Check if the snake has eaten the food
if snake[-1] == food:
food = (random.randint(0, WIDTH - BLOCK_SIZE) // BLOCK_SIZE * BLOCK_SIZE,
random.randint(0, HEIGHT - BLOCK_SIZE) // BLOCK_SIZE * BLOCK_SIZE)
else:
snake.pop(0)
# Check if the snake has collided with the edge or itself
if (snake[-1][0] < 0 or snake[-1][0] >= WIDTH or
snake[-1][1] < 0 or snake[-1][1] >= HEIGHT or
snake[-1] in snake[:-1]):
print("Game Over!")
time.sleep(2)
break
# Draw the game screen
screen.fill(BLACK)
for pos in snake:
pygame.draw.rect(screen, GREEN, (pos[0], pos[1], BLOCK_SIZE, BLOCK_SIZE))
pygame.draw.rect(screen, RED, (food[0], food[1], BLOCK_SIZE, BLOCK_SIZE))
text = font.render(f'Score: {len(snake) - 3}', True, WHITE)
screen.blit(text, (10, 10))
pygame.display.flip()
# Cap the frame rate
pygame.time.Clock().tick(10)
Uploaded model
- Developed by: EpistemeAI
- License: apache-2.0
- Finetuned from model : EpistemeAI/Athene-codegemma-2-7b-it-alpaca-v1.1
This gemma model was trained 2x faster with Unsloth and Huggingface's TRL library.
Notice:
Gemma is provided under and subject to the Gemma Terms of Use found at ai.google.dev/gemma/terms
- Downloads last month
- 17
