repo_description: A course of learning LLM inference serving on Apple Silicon for systems engineers: build a tiny vLLM + Qwen.
repo_topics: course large-language-model llm python qwen qwen2 serving vllm
code: import mlx.core as mx
  from .basics import linear, silu
  from .attention import scaled_dot_product_attention_grouped
  from .layer_norm import RMSNorm
  from .positional_encoding import RoPE
  from typing import Any
  from .embedding import Embedding
  from .quantize import dequantize_linear
  
  
  class Qwen2MultiHeadAttention:
      def __init__(
          self,
          hidden_size: int,
          num_heads: int,
          num_kv_heads: int,
          wq: mx.array,
          wk: mx.array,
          wv: mx.array,
          wo: mx.array,
          bq: mx.array,
          bk: mx.array,
          bv: mx.array,
          max_seq_len: int = 32768,
          theta: int = 1000000,
      ):
          pass
  
      def __call__(
          self,
          x: mx.array,
          mask: mx.array | str | None = None,
      ) -> mx.array:
          pass
  
  
  class Qwen2MLP:
      def __init__(
          self,
          dim: int,
          hidden_dim: int,
          w_gate: mx.array,
          w_up: mx.array,
          w_down: mx.array,
      ):
          pass
  
      def __call__(self, x: mx.array) -> mx.array:
          pass
  
  
  class Qwen2TransformerBlock:
      def __init__(
          self,
          num_attention_heads: int,
          num_kv_heads: int,
          hidden_size: int,
          intermediate_size: int,
          rms_norm_eps: float,
          wq: mx.array,
          wk: mx.array,
          wv: mx.array,
          wo: mx.array,
          bq: mx.array,
          bk: mx.array,
          bv: mx.array,
          w_gate: mx.array,
          w_up: mx.array,
          w_down: mx.array,
          w_input_layernorm: mx.array,
          w_post_attention_layernorm: mx.array,
          max_seq_len: int = 32768,
          theta: int = 1000000,
      ):
          pass
  
      def __call__(
          self,
          x: mx.array,
          mask: mx.array | str | None = None,
      ) -> mx.array:
          pass
  
  
  class Qwen2ModelWeek1:
      def __init__(self, mlx_model: Any):
          pass
  
      def __call__(
          self,
          inputs: mx.array,
      ) -> mx.array:
          pass
  