Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cookbook/client/twinkle/self_congnition.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

logger = get_logger()

# Whether to use Megatron for training
use_megatron = True

# Step 2: Initialize the Twinkle client to communicate with the remote server.
# - base_url: the address of the running Twinkle server
# - api_key: authentication token (loaded from environment variable)
Expand Down Expand Up @@ -88,8 +87,7 @@ def train():
model.set_optimizer('Adam', lr=1e-4)

# Use a linear learning rate scheduler (Do not support LR scheduler if server use megatron)
if not use_megatron:
model.set_lr_scheduler('LinearLR')
model.set_lr_scheduler('LinearLR')

# Step 6: Optionally resume from a previous checkpoint
if resume_path:
Expand Down
19 changes: 6 additions & 13 deletions docs/source_en/Usage Guide/Introduction-with-Qwen3.5.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Qwen3.5-4B Training Best Practices
# Qwen3.5 Training Best Practices

Using Qwen3.5-4B as an example, this guide demonstrates the core capability of the Twinkle framework: **one codebase, from single GPU training to Client-Server mode**.
Using Qwen3.5-4B as an example, this guide demonstrates the core capability of the Twinkle framework: **one component-based code, used from single GPU training to Client-Server mode**.

---

Expand Down Expand Up @@ -364,7 +364,6 @@ Twinkle Client provides an API nearly identical to local training, ideal for sce
import dotenv
dotenv.load_dotenv('.env')

import os
from peft import LoraConfig

from twinkle import get_logger
Expand All @@ -376,9 +375,6 @@ from twinkle_client.model import MultiLoraTransformersModel

logger = get_logger()

# Whether to use the Megatron backend
use_megatron = True

# Initialize the Twinkle client
client = init_twinkle_client(base_url='http://127.0.0.1:8000', api_key='EMPTY_TOKEN')

Expand Down Expand Up @@ -410,11 +406,8 @@ def train():
model.set_template('Template')
model.set_processor('InputProcessor', padding_side='right')
model.set_loss('CrossEntropyLoss')
model.set_optimizer('Adam', lr=1e-4)

# LR scheduler not supported with Megatron backend
if not use_megatron:
model.set_lr_scheduler('LinearLR')
model.set_optimizer('AdamW', lr=1e-4)
model.set_lr_scheduler('LinearLR')

# Resume from checkpoint if available
if resume_path:
Expand Down Expand Up @@ -473,15 +466,15 @@ init_tinker_client()
from tinker import ServiceClient

# Base model
base_model = 'Qwen/Qwen3-30B-A3B-Instruct-2507'
base_model = 'Qwen/Qwen3.5-4B'
base_url = 'http://www.modelscope.cn/twinkle'


def train():
# Prepare dataset
dataset = Dataset(dataset_meta=DatasetMeta('ms://swift/self-cognition', data_slice=range(500)))
dataset.set_template('Template', model_id=f'ms://{base_model}', max_length=256)
dataset.map(SelfCognitionProcessor('twinkle model', 'twinkle team'), load_from_cache_file=False)
dataset.map(SelfCognitionProcessor('Twinkle Model', 'ModelScope Team'), load_from_cache_file=False)
dataset.encode(batched=True, load_from_cache_file=False)
dataloader = DataLoader(dataset=dataset, batch_size=8)

Expand Down
19 changes: 6 additions & 13 deletions docs/source_zh/使用指引/Qwen3.5最佳实践.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Qwen3.5-4B 训练最佳实践
# Qwen3.5 训练最佳实践

本文以 Qwen3.5-4B 为例,演示 Twinkle 框架的核心能力:**一套代码,从单卡训练到Client-Server环境**。
本文以 Qwen3.5-4B 为例,演示 Twinkle 框架的核心能力:**一套组件化代码,从单卡训练到Client-Server环境**。

---

Expand Down Expand Up @@ -364,7 +364,6 @@ Twinkle Client 提供与本地训练几乎完全一致的 API,适合需要精
import dotenv
dotenv.load_dotenv('.env')

import os
from peft import LoraConfig

from twinkle import get_logger
Expand All @@ -376,9 +375,6 @@ from twinkle_client.model import MultiLoraTransformersModel

logger = get_logger()

# 是否使用 Megatron 后端
use_megatron = True

# 初始化 Twinkle 客户端
client = init_twinkle_client(base_url='http://127.0.0.1:8000', api_key='EMPTY_TOKEN')

Expand Down Expand Up @@ -410,11 +406,8 @@ def train():
model.set_template('Template')
model.set_processor('InputProcessor', padding_side='right')
model.set_loss('CrossEntropyLoss')
model.set_optimizer('Adam', lr=1e-4)

# Megatron 后端暂不支持 LR 调度器
if not use_megatron:
model.set_lr_scheduler('LinearLR')
model.set_optimizer('AdamW', lr=1e-4)
model.set_lr_scheduler('LinearLR')

# 恢复训练(如有检查点)
if resume_path:
Expand Down Expand Up @@ -473,15 +466,15 @@ init_tinker_client()
from tinker import ServiceClient

# 基座模型
base_model = 'Qwen/Qwen3-30B-A3B-Instruct-2507'
base_model = 'Qwen/Qwen3.5-4B'
base_url = 'http://www.modelscope.cn/twinkle'


def train():
# 准备数据集
dataset = Dataset(dataset_meta=DatasetMeta('ms://swift/self-cognition', data_slice=range(500)))
dataset.set_template('Template', model_id=f'ms://{base_model}', max_length=256)
dataset.map(SelfCognitionProcessor('twinkle模型', 'twinkle团队'), load_from_cache_file=False)
dataset.map(SelfCognitionProcessor('Twinkle模型', 'ModelScope团队'), load_from_cache_file=False)
dataset.encode(batched=True, load_from_cache_file=False)
dataloader = DataLoader(dataset=dataset, batch_size=8)

Expand Down
Loading