Views
No views yet
Gemma4ForCausalLMGemma4TextConfigGemma4ForCausalLM with a small Gemma4 text MoE configuration.1model_type: gemma4_text
2vocab_size: 1024
3vocab_size_per_layer_input: 1024
4
5hidden_size: 128
6hidden_size_per_layer_input: 16
7intermediate_size: 384
8intermediate_dim: 192
9moe_intermediate_size: 192
10
11num_hidden_layers: 6
12num_attention_heads: 4
13num_key_value_heads: 1
14num_global_key_value_heads: 1
15head_dim: 32
16global_head_dim: 32
17
18sliding_window: 128
19max_position_embeddings: 1024
20
21layer_types:
22 - sliding_attention
23 - sliding_attention
24 - full_attention
25 - sliding_attention
26 - sliding_attention
27 - full_attention
28
29hidden_activation: gelu_pytorch_tanh
30tie_word_embeddings: true
31attention_bias: false
32attention_dropout: 0.0
33rms_norm_eps: 1e-06
34initializer_range: 0.02
35
36use_cache: true
37final_logit_softcapping: null
38use_bidirectional_attention: null
39attention_k_eq_v: false
40num_kv_shared_layers: 0
41use_double_wide_mlp: false
42
43enable_moe_block: true
44num_experts: 4
45top_k_experts: 2
46expert_interval: 2
47router_aux_loss_coef: 0.0
48
49pad_token_id: 1000
50bos_token_id: 1000
51eos_token_id: 1001ssFssFs means sliding_attention and F means full_attention.1enable_moe_block: true
2num_experts: 4
3top_k_experts: 2
4expert_interval: 2
5moe_intermediate_size: 192
6intermediate_dim: 192num_experts=4 and top_k_experts=2 setting is intentional. A smaller configuration such as num_experts=2, top_k=1 would exercise only a much simpler routing path. This checkpoint is intended to cover:1router / gate parameters
2multiple experts
3top-2 expert selection
4weighted expert combination
5MoE FFN parameters
6dense and MoE layer interaction1RawTokenizer(BPE())
2ByteLevel(add_prefix_space=False)
3ByteLevelDecoder()
4BpeTrainer(
5 vocab_size=1000,
6 min_frequency=2,
7 special_tokens=[],
8 initial_alphabet=ByteLevel.alphabet(),
9)1<s> id 1000
2</s> id 1001
3<|im_start|> id 1002vocab_size=1024, leaving a small reserved range above the actual tokenizer size. The pad token is set to <s>, so pad_token_id and bos_token_id are both 1000.ByteLevelBPETokenizer setup that trains special tokens directly into the vocabulary.1num_epochs: 1
2learning_rate: 2e-4
3batch_size: 32
4block_size: 256
5max_steps: derived from one epoch
6
7device: auto
8dtype: float32 by default
9grad_clip: 1.0
10error_on_nonfinite_gradients: true
11weight_decay: 0.0
12seed: 1234
13
14vocab_size: 1024
15base_vocab_size: 1000
16legacy_tokenizer: true
17legacy_special_token_ids: true
18
19hidden_size: 128
20intermediate_size: 384
21moe_intermediate_size: 192
22num_hidden_layers: 6
23num_attention_heads: 4
24num_key_value_heads: 1
25head_dim: 32
26hidden_size_per_layer_input: 16
27layer_pattern: ssFssF
28sliding_window: 128
29max_position_embeddings: 1024
30
31enable_moe_block: true
32num_experts: 4
33top_k_experts: 2
34expert_interval: 2
35router_aux_loss_coef: 0.0Final loss: 1.50301Prompt: Once upon
2
3Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red apple on the ground. She picked it up and showed it to her mom.
4
5"Mommy, look what I found!" Lily said.
6
7"That's a big apple, Lily. It's a special apple. It's very special," her mom replied.1Prompt: There was a little
2
3There was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red apple on the ground. She picked it up and showed it to her mom.
4
5"Mommy, look at the apple!" Lily said.
6
7"That's a nice apple, Lily. It's very pretty," her mom replied.
8
9Lily was happy to have a new apple and wanted to1Prompt: One day
2
3One day, a little girl named Lily went to the park with her mom. She saw a big slide and wanted to try it. But her mom said, "No, Lily. You have to wait. It's not safe."
4
5Lily was sad. She wanted to go on the slide. She asked her mom, "Can I go on the slide?" Her mom said, "No, Lily. You have to wait until the slide is safe."hf/ subdirectory, use the following example.1import torch
2from transformers import PreTrainedTokenizerFast, Gemma4ForCausalLM
3
4repo = "shibatch/tinygemma4moe3m"
5
6tokenizer = PreTrainedTokenizerFast.from_pretrained(repo, subfolder="hf")
7model = Gemma4ForCausalLM.from_pretrained(
8 repo,
9 subfolder="hf",
10 torch_dtype=torch.float32,
11)
12model.eval()
13
14prompt = "Once upon"
15inputs = tokenizer(prompt, return_tensors="pt")
16
17with torch.no_grad():
18 output_ids = model.generate(
19 **inputs,
20 max_new_tokens=100,
21 do_sample=False,
22 pad_token_id=tokenizer.pad_token_id,
23 eos_token_id=tokenizer.eos_token_id,
24 )
25
26print(tokenizer.decode(output_ids[0], skip_special_tokens=True))from transformers import Gemma4ForCausalLM, Gemma4TextConfigPreTrainedTokenizerFast.from transformers import PreTrainedTokenizerFastAutoTokenizer.AutoTokenizer may fail in some environments if the tokenizer backend cannot be inferred automatically.1tokenizer.json
2tokenizer_config.json
3special_tokens_map.json1Gemma4TextConfig
2Gemma4ForCausalLM
3sliding_attention layers
4full_attention layers
5GQA with num_key_value_heads = 1
6global key/value head configuration
7per-layer input embeddings
8tied word embeddings
9Gemma4 RMSNorm behavior
10Gemma4 MLP activation: gelu_pytorch_tanh
11Gemma4 MoE expert parameters
12num_experts = 4
13top_k_experts = 2
14expert_interval = 2
15MoE expert dispatch
16MoE expert output combination
17legacy byte-level BPE tokenizer loading
18generate()
19save_pretrained()
20from_pretrained()1num_experts = 4
2top_k_experts = 2top_k=1 configuration.1sliding_attention
2sliding_attention
3full_attention
4sliding_attention
5sliding_attention
6full_attention1ByteLevel(add_prefix_space=False)
2initial_alphabet=ByteLevel.alphabet()
3special tokens added after BPE trainingPreTrainedTokenizerFast without requiring SentencePiece or tiktoken inference.shibatch/tinygemma4moe3m