Skip to content

Commit 37dc52b

Browse files
Remerge release/0.2 to main (#146)
1 parent 8c3dbc9 commit 37dc52b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+179
-118
lines changed

Dockerfile

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,36 @@ RUN echo "Available release branches:" && git branch -r -l 'origin/release/*' --
1616
echo "Checking out: $LATEST_RELEASE" && \
1717
git checkout --track "$LATEST_RELEASE"
1818

19-
RUN sh INSTALL_MEGATRON.sh
19+
ENV SETUPTOOLS_USE_DISTUTILS=local
2020

21+
# Install base packages
22+
RUN pip install --upgrade peft accelerate transformers "modelscope[framework]" --no-cache-dir
23+
24+
# Install vllm
25+
RUN pip install --upgrade vllm --no-cache-dir
26+
27+
# Install transformer_engine and megatron_core
28+
RUN SITE_PACKAGES=$(python -c "import site; print(site.getsitepackages()[0])") && \
29+
CUDNN_PATH=$SITE_PACKAGES/nvidia/cudnn \
30+
CPLUS_INCLUDE_PATH=$SITE_PACKAGES/nvidia/cudnn/include \
31+
pip install --no-build-isolation "transformer_engine[pytorch]" --no-cache-dir
32+
33+
RUN pip install megatron_core mcore_bridge --no-cache-dir
34+
35+
# Install flash-attention (default arch 8.0;9.0, override via build-arg if needed)
36+
ARG TORCH_CUDA_ARCH_LIST="8.0;9.0"
37+
RUN TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST}" \
38+
MAX_JOBS=8 \
39+
FLASH_ATTENTION_FORCE_BUILD=TRUE \
40+
pip install flash-attn --no-build-isolation --no-cache-dir
41+
42+
RUN pip install flash-linear-attention -U --no-cache-dir
43+
44+
# Install numpy
45+
RUN pip install numpy==2.2 --no-cache-dir
46+
47+
# Install tinker, ray, and other deps
2148
RUN pip install --no-cache-dir tinker==0.14.0 "ray[serve]" transformers peft accelerate -U
2249

50+
# Install twinkle itself
2351
RUN pip install -e . --no-build-isolation

INSTALL_MEGATRON.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ echo "Using CUDA architecture: $TORCH_CUDA_ARCH_LIST"
5656
# Install latest base packages
5757
echo ""
5858
echo "Installing peft, accelerate, transformers, modelscope..."
59-
pip install --upgrade peft accelerate transformers "modelscope[framework]"
59+
pip install --upgrade peft accelerate transformers "modelscope[framework]" --no-cache-dir
6060

6161
# Install latest vllm
6262
echo ""
6363
echo "Installing latest vllm..."
64-
pip install --upgrade vllm
64+
pip install --upgrade vllm --no-cache-dir
6565

6666
# Get site-packages path and install transformer_engine and megatron_core
6767
echo ""
@@ -83,12 +83,12 @@ MAX_JOBS=8 \
8383
FLASH_ATTENTION_FORCE_BUILD=TRUE \
8484
pip install flash-attn --no-build-isolation --no-cache-dir
8585

86-
pip install flash-linear-attention -U
86+
pip install flash-linear-attention -U --no-cache-dir
8787

8888
# Install numpy
8989
echo ""
9090
echo "Installing numpy==2.2 and deep_gemm..."
91-
pip install numpy==2.2
91+
pip install numpy==2.2 --no-cache-dir
9292

9393
# Verify installation
9494
echo ""

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def train():
184184
# 1000 samples
185185
dataset = Dataset(dataset_meta=DatasetMeta('ms://swift/self-cognition', data_slice=range(1000)))
186186
# Set template to prepare encoding
187-
dataset.set_template('Template', model_id=base_model)
187+
dataset.set_template('Qwen3_5Template', model_id=base_model)
188188
# Preprocess the dataset to standard format
189189
dataset.map(SelfCognitionProcessor('twinkle LLM', 'ModelScope Community'))
190190
# Encode dataset
@@ -242,7 +242,7 @@ api_key='your-api-key'
242242

243243
# Use twinkle dataset to load the data
244244
dataset = Dataset(dataset_meta=DatasetMeta('ms://swift/self-cognition', data_slice=range(500)))
245-
dataset.set_template('Template', model_id=base_model, max_length=256)
245+
dataset.set_template('Qwen3_5Template', model_id=base_model, max_length=256)
246246
dataset.map(SelfCognitionProcessor('twinkle Model', 'ModelScope Team'), load_from_cache_file=False)
247247
dataset.encode(batched=True, load_from_cache_file=False)
248248
dataloader = DataLoader(dataset=dataset, batch_size=8)

README_ZH.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def train():
166166
# 1000 samples
167167
dataset = Dataset(dataset_meta=DatasetMeta('ms://swift/self-cognition', data_slice=range(1000)))
168168
# Set template to prepare encoding
169-
dataset.set_template('Template', model_id=base_model)
169+
dataset.set_template('Qwen3_5Template', model_id=base_model)
170170
# Preprocess the dataset to standard format
171171
dataset.map(SelfCognitionProcessor('twinkle LLM', 'ModelScope Community'))
172172
# Encode dataset
@@ -224,7 +224,7 @@ api_key='your-api-key'
224224

225225
# Use twinkle dataset to load the data
226226
dataset = Dataset(dataset_meta=DatasetMeta('ms://swift/self-cognition', data_slice=range(500)))
227-
dataset.set_template('Template', model_id=base_model, max_length=256)
227+
dataset.set_template('Qwen3_5Template', model_id=base_model, max_length=256)
228228
dataset.map(SelfCognitionProcessor('twinkle Model', 'ModelScope Team'), load_from_cache_file=False)
229229
dataset.encode(batched=True, load_from_cache_file=False)
230230
dataloader = DataLoader(dataset=dataset, batch_size=8)

cookbook/client/tinker/modelscope/self_cognition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def train():
3434
dataset = Dataset(dataset_meta=DatasetMeta('ms://swift/self-cognition', data_slice=range(500)))
3535

3636
# Apply the chat template matching the base model (max 256 tokens per sample)
37-
dataset.set_template('Template', model_id=f'ms://{base_model}', max_length=256)
37+
dataset.set_template('Qwen3_5Template', model_id=f'ms://{base_model}', max_length=256)
3838

3939
# Replace placeholder names with custom model/author identity
4040
dataset.map(SelfCognitionProcessor('twinkle模型', 'twinkle团队'), load_from_cache_file=False)

cookbook/client/tinker/modelscope/short_math_grpo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def create_math_dataset():
182182
data_slice=range(DATA_NUM),
183183
)
184184
dataset = Dataset(meta)
185-
dataset.set_template('Template', model_id=BASE_MODEL, max_length=4096, truncation_strategy='delete')
185+
dataset.set_template('Qwen3_5Template', model_id=BASE_MODEL, max_length=4096, truncation_strategy='delete')
186186
dataset.map(MathPreprocessor())
187187
dataset.filter(lambda row: bool(row['messages']))
188188
dataset.encode(add_generation_prompt=True)

cookbook/client/tinker/self_host/self_cognition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def train():
3636
dataset = Dataset(dataset_meta=DatasetMeta('ms://swift/self-cognition', data_slice=range(500)))
3737

3838
# Apply the chat template matching the base model (max 256 tokens per sample)
39-
dataset.set_template('Template', model_id=f'ms://{base_model}', max_length=256)
39+
dataset.set_template('Qwen3_5Template', model_id=f'ms://{base_model}', max_length=256)
4040

4141
# Replace placeholder names with custom model/author identity
4242
dataset.map(SelfCognitionProcessor('twinkle模型', 'twinkle团队'), load_from_cache_file=False)

cookbook/client/tinker/self_host/short_math_grpo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def create_math_dataset():
182182
data_slice=range(DATA_NUM),
183183
)
184184
dataset = Dataset(meta)
185-
dataset.set_template('Template', model_id=BASE_MODEL, max_length=4096, truncation_strategy='delete')
185+
dataset.set_template('Qwen3_5Template', model_id=BASE_MODEL, max_length=4096, truncation_strategy='delete')
186186
dataset.map(MathPreprocessor())
187187
dataset.filter(lambda row: bool(row['messages']))
188188
dataset.encode(add_generation_prompt=True)

cookbook/client/twinkle/modelscope/self_congnition.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def train():
5252
dataset = Dataset(dataset_meta=DatasetMeta('ms://swift/self-cognition', data_slice=range(500)))
5353

5454
# Apply a chat template so the data matches the model's expected input format
55-
dataset.set_template('Template', model_id=f'ms://{base_model}', max_length=512)
55+
dataset.set_template('Qwen3_5Template', model_id=f'ms://{base_model}', max_length=512)
5656

5757
# Replace placeholder names in the dataset with custom model/author names
5858
dataset.map('SelfCognitionProcessor', init_args={'model_name': 'twinkle模型', 'model_author': 'ModelScope社区'})
@@ -77,7 +77,7 @@ def train():
7777
model.add_adapter_to_model('default', lora_config, gradient_accumulation_steps=2)
7878

7979
# Set the same chat template used during data preprocessing
80-
model.set_template('Template')
80+
model.set_template('Qwen3_5Template')
8181

8282
# Set the input processor (pads sequences on the right side)
8383
model.set_processor('InputProcessor', padding_side='right')

cookbook/client/twinkle/self_host/grpo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
def create_gsm8k_dataset():
5757
dataset = Dataset(DatasetMeta('ms://modelscope/gsm8k', subset_name='main', split='train'))
58-
dataset.set_template('Template', model_id=MODEL_ID, max_length=2048)
58+
dataset.set_template('Qwen3_5Template', model_id=MODEL_ID, max_length=2048)
5959
dataset.map('GSM8KProcessor')
6060
dataset.encode(add_generation_prompt=True)
6161
return dataset
@@ -112,11 +112,11 @@ def train():
112112

113113
# Set processor and template for encoding inputs
114114
model.set_processor('InputProcessor')
115-
model.set_template('Template', model_id=MODEL_ID)
115+
model.set_template('Qwen3_5Template', model_id=MODEL_ID)
116116

117117
# Step 4: Configure the sampler
118118
sampler = vLLMSampler(model_id=MODEL_ID)
119-
sampler.set_template('Template', model_id=MODEL_ID)
119+
sampler.set_template('Qwen3_5Template', model_id=MODEL_ID)
120120

121121
# Step 5: Setup metrics and advantage function
122122
advantage_fn = GRPOAdvantage()

0 commit comments

Comments
 (0)