GGUF
conversational
wenhuach's picture
Create README.md
46cc47c verified
metadata
license: apache-2.0
base_model:
  - Qwen/Qwen3-Coder-480B-A35B-Instruct
datasets:
  - codeparrot/github-code-clean

Model Details

This model is a gguf q4km format of Qwen/Qwen3-Coder-480B-A35B-Instruct generated by intel/auto-round algorithm. Embedding layer and lm-head layer are fallback to 8 bits . Please refer to Section Generate the model for more details.

Please follow the license of the original model.

How To Use

Llamacpp inference

/llama-cli -hf Intel/Qwen3-Coder-480B-A35B-Instruct-gguf-q4km-AutoRound:q4_k_m --conversation
> Hi
Hello! How can I help you today?

> code flappy bird in python
# Flappy Bird in Python using Pygame

Here's a complete implementation of Flappy Bird using Pygame:

```python
import pygame
import random
import sys

# Initialize pygame
pygame.init()

# Game constants
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
GRAVITY = 0.25
FLAP_STRENGTH = -5
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1800  # milliseconds
GROUND_HEIGHT = 100
FONT_SIZE = 32

# Colors
SKY_BLUE = (113, 197, 207)
GREEN = (111, 196, 69)
DARK_GREEN = (76, 145, 65)
BIRD_YELLOW = (255, 204, 0)
BIRD_ORANGE = (255, 136, 0)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (231, 76, 60)

# Set up the display
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
clock = pygame.time.Clock()

# Font
font = pygame.font.SysFont(None, FONT_SIZE)
big_font = pygame.font.SysFont(None, FONT_SIZE * 2)

class Bird:
    def __init__(self):
        self.x = SCREEN_WIDTH // 3
        self.y = SCREEN_HEIGHT // 2
        self.velocity = 0
        self.radius = 20
        self.alive = True
        self.flap_count = 0

    def flap(self):
        self.velocity = FLAP_STRENGTH
        self.flap_count += 1

    def update(self):
        # Apply gravity
        self.velocity += GRAVITY
        self.y += self.velocity

        # Keep bird on screen
        if self.y < self.radius:
            self.y = self.radius
            self.velocity = 0

        # Check if bird hit the ground
        if self.y > SCREEN_HEIGHT - GROUND_HEIGHT - self.radius:
            self.y = SCREEN_HEIGHT - GROUND_HEIGHT - self.radius
            self.alive = False

    def draw(self):
        # Draw bird body
        pygame.draw.circle(screen, BIRD_YELLOW, (self.x, self.y), self.radius)

        # Draw bird eye
        pygame.draw.circle(screen, BLACK, (self.x + 10, self.y - 5), 6)
        pygame.draw.circle(screen, WHITE, (self.x + 12, self.y - 7), 2)

        # Draw bird beak
        beak_points = [(self.x + 15, self.y), (self.x + 35, self.y - 5), (self.x + 35, self.y + 5)]
        pygame.draw.polygon(screen, BIRD_ORANGE, beak_points)

        # Draw wing
        wing_y_offset = 5 if self.flap_count % 10 < 5 else -5
        wing_points = [
            (self.x - 10, self.y),
            (self.x - 20, self.y - 10 + wing_y_offset),
            (self.x, self.y + 5 + wing_y_offset)
        ]
        pygame.draw.polygon(screen, BIRD_ORANGE, wing_points)

    def get_rect(self):
        return pygame.Rect(self.x - self.radius, self.y - self.radius,
                          self.radius * 2, self.radius * 2)

class Pipe:
    def __init__(self):
        self.gap_y = random.randint(150, SCREEN_HEIGHT - GROUND_HEIGHT - 150)
        self.x = SCREEN_WIDTH
        self.width = 70
        self.passed = False

    def update(self):
        self.x -= PIPE_SPEED

    def draw(self):
        # Draw top pipe
        pygame.draw.rect(screen, GREEN, (self.x, 0, self.width, self.gap_y - PIPE_GAP // 2))
        pygame.draw.rect(screen, DARK_GREEN, (self.x, self.gap_y - PIPE_GAP // 2 - 20, self.width, 20))

        # Draw bottom pipe
        pipe_top = self.gap_y + PIPE_GAP // 2
        pygame.draw.rect(screen, GREEN, (self.x, pipe_top, self.width, SCREEN_HEIGHT - pipe_top))
        pygame.draw.rect(screen, DARK_GREEN, (self.x, pipe_top, self.width, 20))

    def collide(self, bird):
        bird_rect = bird.get_rect()

        # Top pipe rect
        top_pipe_rect = pygame.Rect(self.x, 0, self.width, self.gap_y - PIPE_GAP // 2)

        # Bottom pipe rect
        bottom_pipe_rect = pygame.Rect(self.x, self.gap_y + PIPE_GAP // 2,
                                      self.width, SCREEN_HEIGHT - self.gap_y - PIPE_GAP // 2)

        return bird_rect.colliderect(top_pipe_rect) or bird_rect.colliderect(bottom_pipe_rect)

class Ground:
    def __init__(self):
        self.y = SCREEN_HEIGHT - GROUND_HEIGHT
        self.height = GROUND_HEIGHT
        self.offset = 0

    def update(self):
        self.offset = (self.offset + PIPE_SPEED) % 40

    def draw(self):
        pygame.draw.rect(screen, (222, 184, 135), (0, self.y, SCREEN_WIDTH, self.height))

        # Draw ground details
        for i in range(0, SCREEN_WIDTH + 40, 40):
            pygame.draw.rect(screen, (210, 150, 100),
                            (i - self.offset, self.y, 20, self.height))

        # Draw grass
        pygame.draw.rect(screen, GREEN, (0, self.y, SCREEN_WIDTH, 15))

def draw_clouds():
    for i in range(5):
        x = (pygame.time.get_ticks() // 50 + i * 100) % (SCREEN_WIDTH + 200) - 100
        y = 50 + i * 30
        pygame.draw.circle(screen, WHITE, (x, y), 20)
        pygame.draw.circle(screen, WHITE, (x + 15, y - 10), 15)
        pygame.draw.circle(screen, WHITE, (x + 15, y + 10), 15)
        pygame.draw.circle(screen, WHITE, (x + 30, y), 20)

def main():
    bird = Bird()
    pipes = []
    ground = Ground()
    score = 0
    last_pipe = pygame.time.get_ticks()
    game_state = "start"  # "start", "playing", "game_over"

    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_state == "start":
                        game_state = "playing"
                    elif game_state == "playing":
                        bird.flap()
                    elif game_state == "game_over":
                        # Reset game
                        bird = Bird()
                        pipes = []
                        score = 0
                        last_pipe = current_time
                        game_state = "playing"

            if event.type == pygame.MOUSEBUTTONDOWN:
                if game_state == "start":
                    game_state = "playing"
                elif game_state == "playing":
                    bird.flap()
                elif game_state == "game_over":
                    # Reset game
                    bird = Bird()
                    pipes = []
                    score = 0
                    last_pipe = current_time
                    game_state = "playing"

        # Fill the background
        screen.fill(SKY_BLUE)

        # Draw clouds
        draw_clouds()

        # Create new pipes
        if game_state == "playing" and current_time - last_pipe > PIPE_FREQUENCY:
            pipes.append(Pipe())
            last_pipe = current_time

        # Update pipes
        for pipe in pipes[:]:
            if game_state == "playing":
                pipe.update()

            pipe.draw()

            # Check for collisions
            if game_state == "playing" and pipe.collide(bird):
                bird.alive = False
                game_state = "game_over"

            # Check if bird passed the pipe
            if not pipe.passed and pipe.x + pipe.width < bird.x:
                pipe.passed = True
                if game_state == "playing":
                    score += 1

            # Remove pipes that are off screen
            if pipe.x + pipe.width < 0:
                pipes.remove(pipe)

        # Update and draw ground
        if game_state == "playing":
            ground.update()
        ground.draw()

        # Update and draw bird
        if game_state == "playing":
            bird.update()
        bird.draw()

        # Check if bird hit the ground
        if not bird.alive and game_state == "playing":
            game_state = "game_over"

        # Draw score
        score_text = font.render(f"Score: {score}", True, WHITE)
        screen.blit(score_text, (10, 10))

        # Draw game state messages
        if game_state == "start":
            title_text = big_font.render("FLAPPY BIRD", True, WHITE)
            screen.blit(title_text, (SCREEN_WIDTH//2 - title_text.get_width()//2, 150))

            start_text = font.render("Press SPACE or CLICK to start", True, WHITE)
            screen.blit(start_text, (SCREEN_WIDTH//2 - start_text.get_width()//2, 250))

        elif game_state == "game_over":
            game_over_text = big_font.render("GAME OVER", True, RED)
            screen.blit(game_over_text, (SCREEN_WIDTH//2 - game_over_text.get_width()//2, 150))

            final_score = font.render(f"Score: {score}", True, WHITE)
            screen.blit(final_score, (SCREEN_WIDTH//2 - final_score.get_width()//2, 220))

            restart_text = font.render("Press SPACE or CLICK to restart", True, WHITE)
            screen.blit(restart_text, (SCREEN_WIDTH//2 - restart_text.get_width()//2, 270))

        # Update the display
        pygame.display.flip()

        # Cap the frame rate
        clock.tick(60)

if __name__ == "__main__":
    main()
```

## How to Play:
1. Press SPACE or click the mouse to start the game
2. Press SPACE or click the mouse to make the bird flap and fly upward
3. Navigate through the pipes without hitting them
4. Each pipe you pass gives you 1 point
5. If you hit a pipe or the ground, the game ends
6. Press SPACE or click to restart after game over

## Features:
- Smooth bird physics with gravity and flapping
- Randomly generated pipes with consistent gaps
- Animated bird with flapping wings
- Scrolling ground with texture
- Moving clouds in the background
- Score tracking
- Start screen and game over screen
- Visual feedback for collisions

## Requirements:
- Python 3.x
- Pygame library (install with `pip install pygame`)

The game includes all the core mechanics of Flappy Bird:
- Bird movement with gravity
- Pipe obstacles to navigate through
- Collision detection
- Score tracking
- Game states (start, playing, game over)

Enjoy playing!



Generate the model

Here is the sample command to reproduce the model. 3*80G

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
import transformers
from auto_round import AutoRound

model_name = "Qwen/Qwen3-Coder-480B-A35B-Instruct"

tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="cpu", torch_dtype="auto", trust_remote_code=True)

block = model.model.layers
device_map = {}
layer_config = {}
for n, m in model.named_modules():
    if n == "lm_head" or isinstance(m, torch.nn.Embedding):
        layer_config[n] = {"bits": 8}

for n, m in block.named_modules():
    if isinstance(m, (torch.nn.Linear, transformers.modeling_utils.Conv1D)):
        if "experts" in n and ("shared_experts" not in n):
            if int(n.split('.')[-2]) < 30:
                device = "cuda:0"
            elif int(n.split('.')[-2]) >= 30 and int(n.split('.')[-2]) < 95:
                device = "cuda:1"

            elif int(n.split('.')[-2]) >= 95:
                device = "cuda:2"
        else:
            device = "cuda:0"

        n = n[2:]

        device_map.update({n: device})

autoround = AutoRound(
    model=model, tokenizer=tokenizer, device_map=device_map, nsamples=512, dataset="github-code-clean",
    layer_config=layer_config, low_gpu_mem_usage=True)
autoround.quantize_and_save(format="gguf:q4_k_m", output_dir="/dataset/Qwen3-Coder-480B-A35B-Instruct-q4km")

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

arxiv github