family: qwen3_5
display_name: "Qwen3.5"
vendor: Alibaba
architectures:
  - Qwen3_5ForCausalLM
  - Qwen3_5ForConditionalGeneration
hf_pattern: "Qwen/Qwen3.5*"

size_variants:
  9b:
    parameters: "9B"
    hidden_dim: 4096
    num_layers: 32
    num_heads: 16
    num_kv_heads: 4
    intermediate_dim: 12288
    vocab_size: 248320
    max_position_embeddings: 262144
    head_dim: 256
    rope_theta: 1000000.0
    rms_norm_eps: 0.000001
  27b:
    parameters: "27B"
    hidden_dim: 5120
    num_layers: 64
    num_heads: 24
    num_kv_heads: 4
    intermediate_dim: 17408
    vocab_size: 248320
    max_position_embeddings: 262144
    head_dim: 256
    rope_theta: 10000000.0
    rms_norm_eps: 0.000001

constraints:
  attention_type: gqa
  activation: silu
  norm_type: rmsnorm
  has_bias: false
  tied_embeddings: false
  positional_encoding: rope
  mlp_type: swiglu

tensor_template:
  embedding: "model.embed_tokens.weight"
  lm_head: "lm_head.weight"
  final_norm: "model.norm.weight"
  per_layer:
    q_proj: "model.layers.{n}.self_attn.q_proj.weight"
    k_proj: "model.layers.{n}.self_attn.k_proj.weight"
    v_proj: "model.layers.{n}.self_attn.v_proj.weight"
    o_proj: "model.layers.{n}.self_attn.o_proj.weight"
    gate_proj: "model.layers.{n}.mlp.gate_proj.weight"
    up_proj: "model.layers.{n}.mlp.up_proj.weight"
    down_proj: "model.layers.{n}.mlp.down_proj.weight"
    input_layernorm: "model.layers.{n}.input_layernorm.weight"
    post_attention_layernorm: "model.layers.{n}.post_attention_layernorm.weight"

shape_template:
  embedding: "[vocab_size, hidden_dim]"
  lm_head: "[vocab_size, hidden_dim]"
  q_proj: "[num_heads * head_dim, hidden_dim]"
  k_proj: "[num_kv_heads * head_dim, hidden_dim]"
  v_proj: "[num_kv_heads * head_dim, hidden_dim]"
  o_proj: "[hidden_dim, num_heads * head_dim]"
  gate_proj: "[intermediate_dim, hidden_dim]"
  up_proj: "[intermediate_dim, hidden_dim]"
  down_proj: "[hidden_dim, intermediate_dim]"
  input_layernorm: "[hidden_dim]"
  post_attention_layernorm: "[hidden_dim]"

quantizations:
  - q4_k_m
  - q5_k_m
  - q6_k
  - q8_0
  - f16
  - f32

chat_template:
  format: chatml
  template: "{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}"
  bos_token: ""
  eos_token: "<|im_end|>"
  special_tokens:
    im_start: "<|im_start|>"
    im_end: "<|im_end|>"
    endoftext: "<|endoftext|>"

certification:
  playbook_path: "../apr-model-qa-playbook/playbooks/models/qwen3.5-{size}.playbook.yaml"
  csv_family_key: "qwen3_5"
  size_categories:
    9b: medium
    27b: large
