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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
---
license: mit
base_model:
- deepseek-ai/DeepSeek-R1-0528
---




## Model Details

This model is a mixed gguf:q2ks of [deepseek-ai/DeepSeek-R1-0528](https://huggingface.co/deepseek-ai/DeepSeek-R1-0528) generated by [intel/auto-round](https://github.com/intel/auto-round) algorithm. Please refer to Section `Generate the model` for more details.

## How To Use

~~~bash
./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

~~~python
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

```python
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](https://github.com/intel/neural-compressor)

## 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} }

[arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)