Model Details
This model is a mixed gguf:q2ks of deepseek-ai/DeepSeek-R1-0528 generated by intel/auto-round algorithm. Please refer to Section Generate the model
for more details.
How To Use
./llama-cli --model ./DeepSeek-R1-0528-hf-256x20B-Q2_K_S-00001-of-00005.gguf --prompt "<|User|>Create a Flappy Bird game in Python.<|Assistant|>"
LLamacpp Inference
Create a Flappy Bird game in Python.<think>
We'll use Pygame to create a Flappy Bird game.
Steps:
1. Import pygame and initialize it.
2. Set up the game window.
3. Create the bird (a rectangle or an image) and define its movement (gravity and flap).
4. Create pipes (obstacles) that move from right to left. They have a gap for the bird to pass through.
5. Check for collisions between the bird and the pipes, or if the bird hits the ground or ceiling.
6. Keep score (each pipe passed increases score).
7. Game over when collision occurs, then restart.
Let's break down the code into sections:
- Constants for window size, colors, bird and pipe dimensions, gravity, etc.
- Bird class (or functions to handle bird)
- Pipe class to manage pipes (position, movement, drawing)
- Main game loop: handle events, update positions, check collisions, draw everything.
We'll keep it simple without using images, but with shapes.
Plan:
Constants:
WIDTH, HEIGHT: window dimensions.
GRAVITY: constant downward acceleration.
FLAP_FORCE: upward velocity when bird flaps.
PIPE_WIDTH: width of each pipe.
PIPE_GAP: gap between top and bottom pipe.
PIPE_SPEED: how fast pipes move to the left.
PIPE_FREQUENCY: how often new pipes are generated (every n frames).
Bird:
x, y: position (x fixed, y changes)
velocity: current vertical velocity.
flap: function to apply upward velocity.
Pipe:
Each pipe pair has a top pipe and a bottom pipe.
x: position (right edge of the pipe).
gap_y: the vertical position of the gap (center of the gap).
passed: flag to indicate if the bird has passed this pipe (for scoring).
We'll manage:
bird = Bird(start_x, start_y)
pipes = list of Pipe objects.
Steps in main loop:
- Handle events (key presses: space or mouse click to flap; quit event).
- Update bird: apply gravity, update position.
- Update pipes: move them left, remove pipes that are off-screen, generate new pipes periodically.
- Check collisions:
bird with ground or ceiling -> game over.
bird with any pipe -> game over.
If bird passes a pipe (without having passed it before) -> increase score.
- Draw everything: background, bird, pipes, and score.
Let's code accordingly.
</think>
# Flappy Bird Game in Python using Pygame
Here's a complete implementation of the Flappy Bird game using Pygame:
```python
import pygame
import sys
import random
# Initialize pygame
pygame.init()
# Game constants
WIDTH, HEIGHT = 400, 600
FPS = 60
GRAVITY = 0.5
FLAP_POWER = -8
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
FLOOR_HEIGHT = 100
BIRD_SIZE = 30
# Colors
SKY_BLUE = (135, 206, 235)
GREEN = (0, 128, 0)
RED = (255, 0, 0)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
YELLOW = (255, 255, 0)
BROWN = (139, 69, 19)
# Setup the display
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Flappy Bird")
clock = pygame.time.Clock()
# Font setup
font = pygame.font.SysFont('Arial', 40)
small_font = pygame.font.SysFont('Arial', 24)
class Bird:
def __init__(self):
self.x = WIDTH // 4
self.y = HEIGHT // 2
self.velocity = 0
self.alive = True
self.rect = pygame.Rect(self.x - BIRD_SIZE//2, self.y - BIRD_SIZE//2, BIRD_SIZE, BIRD_SIZE)
def flap(self):
self.velocity = FLAP_POWER
def update(self):
# Apply gravity
self.velocity += GRAVITY
self.y += self.velocity
# Update rectangle position
self.rect.y = self.y - BIRD_SIZE//2
# Check boundaries
if self.y < 0:
self.y = 0
self.velocity = 0
if self.y > HEIGHT - FLOOR_HEIGHT:
self.y = HEIGHT - FLOOR_HEIGHT
self.velocity = 0
self.alive = False
def draw(self):
# Draw bird body
pygame.draw.circle(screen, YELLOW, (self.x, self.y), BIRD_SIZE//2)
# Draw bird eye
pygame.draw.circle(screen, BLACK, (self.x + 8, self.y - 5), 4)
# Draw bird beak
pygame.draw.polygon(screen, RED, [
(self.x + 15, self.y),
(self.x + 30, self.y),
(self.x + 15, self.y + 5)
])
# Draw bird wing
wing_y = self.y + 5
if self.velocity < 0: # Flapping up
wing_y -= 5
pygame.draw.ellipse(screen, RED, (self.x - 20, wing_y, 15, 10))
# Draw collision rectangle for debugging (comment out for final version)
# pygame.draw.rect(screen, RED, self.rect, 2)
class Pipe:
def __init__(self):
self.gap_y = random.randint(150, HEIGHT - PIPE_GAP - 150)
self.x = WIDTH
self.passed = False
self.top_rect = pygame.Rect(self.x, 0, 60, self.gap_y)
self.bottom_rect = pygame.Rect(self.x, self.gap_y + PIPE_GAP, 60, HEIGHT)
def update(self):
self.x -= PIPE_SPEED
self.top_rect.x = self.x
self.bottom_rect.x = self.x
def draw(self):
# Draw top pipe
pygame.draw.rect(screen, GREEN, self.top_rect)
pygame.draw.rect(screen, (0, 100, 0), self.top_rect, 3)
# Draw pipe cap (top)
pygame.draw.rect(screen, (0, 100, 0), (self.x - 5, self.gap_y - 20, 70, 20))
# Draw bottom pipe
pygame.draw.rect(screen, GREEN, self.bottom_rect)
pygame.draw.rect(screen, (0, 100, 0), self.bottom_rect, 3)
# Draw pipe cap (bottom)
pygame.draw.rect(screen, (0, 100, 0), (self.x - 5, self.gap_y + PIPE_GAP, 70, 20))
def is_off_screen(self):
return self.x + 60 < 0
def check_collision(self, bird):
return self.top_rect.colliderect(bird.rect) or self.bottom_rect.colliderect(bird.rect)
def draw_background():
# Sky background
screen.fill(SKY_BLUE)
# Draw clouds
for cloud in clouds:
pygame.draw.ellipse(screen, WHITE, cloud)
# Draw floor
pygame.draw.rect(screen, BROWN, (0, HEIGHT - FLOOR_HEIGHT, WIDTH, FLOOR_HEIGHT))
# Draw grass
for i in range(0, WIDTH, 20):
pygame.draw.line(screen, GREEN, (i, HEIGHT - FLOOR_HEIGHT),
(i + 10, HEIGHT - FLOOR_HEIGHT - 15), 2)
def draw_score(score):
score_text = font.render(f"Score: {score}", True, WHITE)
screen.blit(score_text, (WIDTH // 2 - score_text.get_width() // 2, 20))
def draw_game_over(score):
# Semi-transparent overlay
overlay = pygame.Surface((WIDTH, HEIGHT))
overlay.set_alpha(180)
overlay.fill(BLACK)
screen.blit(overlay, (0, 0))
# Game over text
game_over_text = font.render("GAME OVER", True, RED)
screen.blit(game_over_text, (WIDTH // 2 - game_over_text.get_width() // 2, HEIGHT // 3))
# Score text
score_text = font.render(f"Final Score: {score}", True, WHITE)
screen.blit(score_text, (WIDTH // 2 - score_text.get_width() // 2, HEIGHT // 2))
# Restart instructions
restart_text = small_font.render("Press SPACE to restart", True, WHITE)
screen.blit(restart_text, (WIDTH // 2 - restart_text.get_width() // 2, HEIGHT // 2 + 80))
def main():
global clouds
# Initialize clouds
clouds = [
pygame.Rect(50, 80, 60, 30),
pygame.Rect(200, 50, 80, 40),
pygame.Rect(300, 120, 70, 35),
pygame.Rect(150, 180, 90, 25)
]
# Game variables
bird = Bird()
pipes = []
score = 0
last_pipe = pygame.time.get_ticks()
game_active = True
# Main game loop
while True:
current_time = pygame.time.get_ticks()
# Event handling
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
if game_active:
bird.flap()
else:
# Reset game
bird = Bird()
pipes = []
score = 0
last_pipe = current_time
game_active = True
if game_active:
# Update bird
bird.update()
# Generate new pipes
if current_time - last_pipe > PIPE_FREQUENCY:
pipes.append(Pipe())
last_pipe = current_time
# Update pipes
for pipe in pipes[:]:
pipe.update()
# Check for collisions
if pipe.check_collision(bird):
bird.alive = False
game_active = False
# Check if pipe is off screen
if pipe.is_off_screen():
pipes.remove(pipe)
# Check if bird has passed the pipe
if not pipe.passed and pipe.x + 60 < bird.x:
pipe.passed = True
score += 1
# Check if bird is alive
if not bird.alive:
game_active = False
# Drawing
draw_background()
# Draw pipes
for pipe in pipes:
pipe.draw()
# Draw bird
bird.draw()
# Draw score
draw_score(score)
# Draw game over screen if not active
if not game_active:
draw_game_over(score)
# Update display
pygame.display.flip()
clock.tick(FPS)
if __name__ == "__main__":
main()
```
## How to Play:
1. Press the SPACE key to make the bird flap and fly upward.
2. Navigate through the pipes without hitting them.
3. Each pipe you pass gives you 1 point.
4. If you hit a pipe or the ground, the game ends.
5. Press SPACE after the game ends to restart.
## Features:
- Bird character with animated flapping wings
- Randomly generated pipes with varying gap positions
- Cloud decorations in the background
- Score display
- Game over screen with restart option
- Physics-based bird movement with gravity
- Collision detection
## Requirements:
- Python 3.x
- Pygame library (install with `pip install pygame`)
The game includes visual enhancements like:
- Detailed bird with eyes, beak, and wing
- Pipe caps for a more realistic look
- Animated clouds
- Grass details on the ground
- Smooth physics for the bird movement
Enjoy playing your Flappy Bird game!
Generate the model
auto-round>0.5.1
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from auto_round import AutoRound
model_name = "/models/DeepSeek-R1-0528-hf" ##must be BF16 model
model = AutoModelForCausalLM.from_pretrained(model_name,
device_map="cpu", torch_dtype="auto")
tokenizer = AutoTokenizer.from_pretrained(model_name)
layer_config = {}
for n, m in model.named_modules():
if n == "lm_head" or isinstance(m, torch.nn.Embedding):
layer_config[n] = {"bits": 8}
elif isinstance(m, torch.nn.Linear) and (not "expert" in n or "shared_experts" in n) and n != "lm_head":
layer_config[n] = {"bits": 4}
autoround = AutoRound(model, tokenizer, iters=0, layer_config=layer_config, batch_size=8, nsamples=512, low_gpu_mem_usage=True)
autoround.quantize_and_save("/models/DeepSeek-R1-0528-q2ks", format="gguf:q2_k_s")
Ethical Considerations and Limitations
The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
Therefore, before deploying any applications of the model, developers should perform safety testing.
Caveats and Recommendations
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
Here are a couple of useful links to learn more about Intel's AI software:
- Intel Neural Compressor link
Disclaimer
The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
Cite
@article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
- Downloads last month
- 3,312
2-bit
Model tree for Intel/DeepSeek-R1-0528-q2ks-mixed-AutoRound-inc-v1
Base model
deepseek-ai/DeepSeek-R1-0528