-
Notifications
You must be signed in to change notification settings - Fork 212
feat: add GLM-4.7-Flash EAGLE3 training support #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "architectures": [ | ||
| "LlamaForCausalLMEagle3" | ||
| ], | ||
| "attention_bias": false, | ||
| "attention_dropout": 0.0, | ||
| "bos_token_id": 151329, | ||
| "eos_token_id": 151336, | ||
| "head_dim": 102, | ||
| "hidden_act": "silu", | ||
| "hidden_size": 2048, | ||
| "initializer_range": 0.02, | ||
| "intermediate_size": 8192, | ||
| "max_position_embeddings": 4096, | ||
| "model_type": "llama", | ||
| "num_attention_heads": 20, | ||
| "num_hidden_layers": 1, | ||
| "num_key_value_heads": 4, | ||
| "rms_norm_eps": 1e-05, | ||
| "rope_theta": 1000000, | ||
| "tie_word_embeddings": false, | ||
| "torch_dtype": "bfloat16", | ||
| "use_cache": true, | ||
| "vocab_size": 154880, | ||
| "draft_vocab_size": 32000 | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||||||
| #!/bin/bash | ||||||||||
| # GLM-4.7-Flash EAGLE3 Debug Training Script | ||||||||||
| # Quick test run with verbose logging | ||||||||||
|
|
||||||||||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||||||||||
| ROOT_DIR=$(dirname $SCRIPT_DIR) | ||||||||||
| export TORCHINDUCTOR_CACHE_DIR=$ROOT_DIR/cache/compiled_kernels | ||||||||||
|
|
||||||||||
| # Load wandb API key from persistent storage | ||||||||||
| if [ -f /gustavo/.wandb_key ]; then | ||||||||||
| export WANDB_API_KEY=$(cat /gustavo/.wandb_key) | ||||||||||
| fi | ||||||||||
|
Comment on lines
+10
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script hardcodes a path to a secret file
Suggested change
|
||||||||||
|
|
||||||||||
| NUM_GPUS=1 | ||||||||||
| TP_SIZE=1 | ||||||||||
| BUILD_DATASET_NUM_PROC=64 | ||||||||||
|
|
||||||||||
| echo "========================================" | ||||||||||
| echo "GLM-4.7-Flash EAGLE3 DEBUG Training" | ||||||||||
| echo "========================================" | ||||||||||
| echo "NUM_GPUS: $NUM_GPUS" | ||||||||||
| echo "TP_SIZE: $TP_SIZE" | ||||||||||
| echo "Testing with 1 epoch, verbose logging" | ||||||||||
| echo "Using single GPU for debugging" | ||||||||||
| echo "Loss debugging ENABLED" | ||||||||||
| echo "========================================" | ||||||||||
|
|
||||||||||
| torchrun \ | ||||||||||
| --standalone \ | ||||||||||
| --nproc_per_node $NUM_GPUS \ | ||||||||||
| $ROOT_DIR/scripts/train_eagle3.py \ | ||||||||||
| --target-model-path zai-org/GLM-4.7-Flash \ | ||||||||||
| --trust-remote-code \ | ||||||||||
| --draft-model-config $ROOT_DIR/configs/glm4-flash-eagle3.json \ | ||||||||||
| --train-data-path $ROOT_DIR/cache/dataset/sharegpt_train.jsonl \ | ||||||||||
| --build-dataset-num-proc $BUILD_DATASET_NUM_PROC \ | ||||||||||
| --output-dir $ROOT_DIR/outputs/glm4-flash-eagle3-debug \ | ||||||||||
| --num-epochs 1 \ | ||||||||||
| --batch-size 1 \ | ||||||||||
| --learning-rate 1e-4 \ | ||||||||||
| --max-length 512 \ | ||||||||||
| --chat-template glm4 \ | ||||||||||
| --cache-dir $ROOT_DIR/cache \ | ||||||||||
| --embedding-key model.embed_tokens.weight \ | ||||||||||
| --tp-size $TP_SIZE \ | ||||||||||
| --target-model-backend sglang \ | ||||||||||
| --sglang-mem-fraction-static 0.75 \ | ||||||||||
| --log-interval 10 \ | ||||||||||
| --save-interval 500 \ | ||||||||||
| --eval-interval 500 \ | ||||||||||
| --verbose \ | ||||||||||
| --debug-loss \ | ||||||||||
| --report-to wandb \ | ||||||||||
| --wandb-project baby-shark-glm-eagle3 \ | ||||||||||
| --wandb-name glm4-flash-eagle3-debug-$(date +%Y%m%d-%H%M%S) | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||||
| #!/bin/bash | ||||||||||
| # GLM-4.7-Flash EAGLE3 Training Script | ||||||||||
| # Usage: ./examples/run_glm4_flash_eagle3_online.sh [NUM_GPUS] [TP_SIZE] | ||||||||||
|
|
||||||||||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||||||||||
| ROOT_DIR=$(dirname $SCRIPT_DIR) | ||||||||||
| export TORCHINDUCTOR_CACHE_DIR=$ROOT_DIR/cache/compiled_kernels | ||||||||||
|
|
||||||||||
| # Load wandb API key from persistent storage | ||||||||||
| if [ -f /gustavo/.wandb_key ]; then | ||||||||||
| export WANDB_API_KEY=$(cat /gustavo/.wandb_key) | ||||||||||
| fi | ||||||||||
|
Comment on lines
+10
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script hardcodes a path to a secret file
Suggested change
|
||||||||||
|
|
||||||||||
| NUM_GPUS=${1:-1} | ||||||||||
| TP_SIZE=${2:-1} | ||||||||||
| BUILD_DATASET_NUM_PROC=${BUILD_DATASET_NUM_PROC:-64} | ||||||||||
|
|
||||||||||
| echo "========================================" | ||||||||||
| echo "GLM-4.7-Flash EAGLE3 Training" | ||||||||||
| echo "========================================" | ||||||||||
| echo "NUM_GPUS: $NUM_GPUS" | ||||||||||
| echo "TP_SIZE: $TP_SIZE" | ||||||||||
| echo "BUILD_DATASET_NUM_PROC: $BUILD_DATASET_NUM_PROC" | ||||||||||
| echo "========================================" | ||||||||||
|
|
||||||||||
| torchrun \ | ||||||||||
| --standalone \ | ||||||||||
| --nproc_per_node $NUM_GPUS \ | ||||||||||
| $ROOT_DIR/scripts/train_eagle3.py \ | ||||||||||
| --target-model-path zai-org/GLM-4.7-Flash \ | ||||||||||
|
Comment on lines
+28
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The script uses unquoted positional arguments Recommendation: Quote the variables (e.g., |
||||||||||
| --trust-remote-code \ | ||||||||||
| --draft-model-config $ROOT_DIR/configs/glm4-flash-eagle3.json \ | ||||||||||
| --train-data-path $ROOT_DIR/cache/dataset/sharegpt_train.jsonl \ | ||||||||||
| --build-dataset-num-proc $BUILD_DATASET_NUM_PROC \ | ||||||||||
| --output-dir $ROOT_DIR/outputs/glm4-flash-eagle3-sharegpt \ | ||||||||||
| --num-epochs 10 \ | ||||||||||
| --batch-size 1 \ | ||||||||||
| --learning-rate 1e-4 \ | ||||||||||
| --max-length 4096 \ | ||||||||||
| --chat-template glm4 \ | ||||||||||
| --cache-dir $ROOT_DIR/cache \ | ||||||||||
| --embedding-key model.embed_tokens.weight \ | ||||||||||
| --tp-size $TP_SIZE \ | ||||||||||
| --target-model-backend sglang \ | ||||||||||
| --sglang-mem-fraction-static 0.4 | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #!/usr/bin/env python3 | ||
| """Mix multiple datasets according to specified ratios.""" | ||
| import json | ||
| import random | ||
| from pathlib import Path | ||
| from typing import List, Tuple | ||
|
|
||
| def load_jsonl(path: str) -> List[dict]: | ||
| """Load JSONL file.""" | ||
| data = [] | ||
| with open(path, 'r') as f: | ||
| for line in f: | ||
| data.append(json.loads(line)) | ||
| return data | ||
|
|
||
| def mix_datasets( | ||
| datasets: List[Tuple[str, float]], # [(path, ratio)] | ||
| output_path: str, | ||
| total_samples: int = None, | ||
| seed: int = 42 | ||
| ): | ||
| """Mix datasets according to ratios.""" | ||
| random.seed(seed) | ||
|
|
||
| # Load all datasets | ||
| all_data = [] | ||
| for path, ratio in datasets: | ||
| data = load_jsonl(path) | ||
| print(f"Loaded {len(data)} samples from {path}") | ||
|
|
||
| if total_samples: | ||
| # Sample according to ratio | ||
| n_samples = int(total_samples * ratio) | ||
| sampled = random.sample(data, min(n_samples, len(data))) | ||
| else: | ||
| # Use all data weighted by ratio | ||
| sampled = random.sample(data, int(len(data) * ratio / sum(r for _, r in datasets))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| all_data.extend(sampled) | ||
| print(f"Added {len(sampled)} samples ({ratio*100:.1f}%)") | ||
|
|
||
| # Shuffle combined dataset | ||
| random.shuffle(all_data) | ||
|
|
||
| # Normalize IDs to strings (fix type mismatch between datasets) | ||
| for i, item in enumerate(all_data): | ||
| item['id'] = str(item.get('id', i)) | ||
|
|
||
| # Save mixed dataset | ||
| with open(output_path, 'w') as f: | ||
| for item in all_data: | ||
| f.write(json.dumps(item) + '\n') | ||
|
|
||
| print(f"\nSaved {len(all_data)} mixed samples to {output_path}") | ||
|
|
||
| if __name__ == "__main__": | ||
| import argparse | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--output", type=str, required=True) | ||
| parser.add_argument("--total-samples", type=int, default=None) | ||
| parser.add_argument("--seed", type=int, default=42) | ||
| args = parser.parse_args() | ||
|
|
||
| # Mix for Experiment J: 45% ShareGPT, 35% UltraChat, 20% PerfectBlend | ||
| base_dir = Path(__file__).parent.parent / "cache" / "dataset" | ||
| datasets = [ | ||
| (str(base_dir / "sharegpt_train.jsonl"), 0.45), | ||
| (str(base_dir / "ultrachat_train.jsonl"), 0.35), | ||
| (str(base_dir / "perfectblend_train.jsonl"), 0.20), | ||
| ] | ||
|
|
||
| mix_datasets( | ||
| datasets=datasets, | ||
| output_path=args.output, | ||
| total_samples=args.total_samples, | ||
| seed=args.seed | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
head_dimis set to 102. While this is a valid configuration, it's not a multiple of 8. This can lead to suboptimal performance on modern hardware accelerators like GPUs, which often have optimized kernels for dimensions that are multiples of 8 or 64. If this value is not a strict requirement of the model architecture, consider adjusting it to a nearby multiple of 8 (e.g., 104 or 96) to potentially improve training and inference speed.