Skip to content

Commit c400468

Browse files
committed
2 parents ccc5e63 + 9306f8d commit c400468

169 files changed

Lines changed: 10832 additions & 41387 deletions

File tree

Some content is hidden

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

.github/workflows/all-tests-nvidia.yml

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ name: All Tests Nvidia
33
on:
44
push:
55
branches: ["main"]
6+
paths-ignore:
7+
- 'hardware/**'
68
pull_request:
79
branches: ["main"]
10+
paths-ignore:
11+
- 'hardware/**'
812

913
concurrency:
1014
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.actor }}
@@ -21,8 +25,8 @@ jobs:
2125
run: |
2226
echo "ci_image=localhost:5000/flagscale:cuda12.8.1-cudnn9.7.1-python3.12-torch2.7.0-time2507111538" >> $GITHUB_OUTPUT # Set output variable
2327
24-
# Megatron Unit Tests with Matrix
25-
megatron-unit-tests:
28+
# Train Megatron Unit Tests with Matrix
29+
unit_tests_train_megatron:
2630
needs:
2731
- set-env
2832
uses: ./.github/workflows/unit-tests-nvidia.yml
@@ -43,34 +47,51 @@ jobs:
4347
- transformer/moe
4448
- transformer
4549
- ./
46-
name: "megatron-${{ matrix.subset == './' && 'root' || matrix.subset }}"
50+
name: "train_megatron-${{ matrix.subset == './' && 'root' || matrix.subset }}"
4751
with:
48-
backend: megatron
52+
backend: train_megatron
4953
subset: ${{ matrix.subset }}
5054
image: ${{ needs.set-env.outputs.ci_image }}
5155

52-
# Flagscale Unit Tests with Matrix
53-
flagscale-unit-tests:
56+
# Train Flagscale Unit Tests with Matrix
57+
unit_tests_train_flagscale:
5458
needs:
5559
- set-env
56-
- megatron-unit-tests
60+
- unit_tests_train_megatron
5761
uses: ./.github/workflows/unit-tests-nvidia.yml
5862
strategy:
5963
matrix:
6064
subset:
6165
- runner
6266
- ./
63-
name: "flagscale-${{ matrix.subset == './' && 'root' || matrix.subset }}"
67+
name: "train_flagscale-${{ matrix.subset == './' && 'root' || matrix.subset }}"
6468
with:
65-
backend: flagscale
69+
backend: train_flagscale
70+
subset: ${{ matrix.subset }}
71+
image: ${{ needs.set-env.outputs.ci_image }}
72+
73+
# Inference Flagscale Unit Tests with Matrix
74+
unit_tests_inference_flagscale:
75+
needs:
76+
- set-env
77+
- unit_tests_train_flagscale
78+
uses: ./.github/workflows/unit-tests-nvidia.yml
79+
strategy:
80+
matrix:
81+
subset:
82+
- inference
83+
- transforms
84+
name: "inference_flagscale-${{ matrix.subset == './' && 'root' || matrix.subset }}"
85+
with:
86+
backend: inference_flagscale
6687
subset: ${{ matrix.subset }}
6788
image: ${{ needs.set-env.outputs.ci_image }}
6889

6990
# Functional Tests with Mision and Type Matrix
70-
functional-tests-train:
91+
functional_tests_train:
7192
needs:
7293
- set-env
73-
- flagscale-unit-tests
94+
- unit_tests_inference_flagscale
7495
uses: ./.github/workflows/functional-tests-nvidia.yml
7596
strategy:
7697
matrix:
@@ -85,10 +106,10 @@ jobs:
85106
type: train
86107
image: ${{ needs.set-env.outputs.ci_image }}
87108

88-
functional-tests-hetero:
109+
functional_tests_hetero:
89110
needs:
90111
- set-env
91-
- functional-tests-train
112+
- functional_tests_train
92113
# TODO: test need fix
93114
uses: ./.github/workflows/functional-tests-nvidia.yml
94115
strategy:
@@ -101,10 +122,10 @@ jobs:
101122
type: hetero_train
102123
image: ${{ needs.set-env.outputs.ci_image }}
103124

104-
functional-tests-inference:
125+
functional_tests_inference:
105126
needs:
106127
- set-env
107-
- functional-tests-hetero
128+
- functional_tests_hetero
108129
uses: ./.github/workflows/functional-tests-nvidia.yml
109130
strategy:
110131
matrix:
@@ -119,10 +140,10 @@ jobs:
119140
type: inference
120141
image: ${{ needs.set-env.outputs.ci_image }}
121142

122-
functional-tests-serve:
143+
functional_tests_serve:
123144
needs:
124145
- set-env
125-
- functional-tests-inference
146+
- functional_tests_inference
126147
uses: ./.github/workflows/functional-tests-nvidia.yml
127148
strategy:
128149
matrix:
@@ -135,10 +156,10 @@ jobs:
135156
type: serve
136157
image: ${{ needs.set-env.outputs.ci_image }}
137158

138-
functional-tests-rl:
159+
functional_tests_rl:
139160
needs:
140161
- set-env
141-
- functional-tests-serve
162+
- functional_tests_serve
142163
uses: ./.github/workflows/functional-tests-nvidia.yml
143164
strategy:
144165
matrix:
@@ -153,11 +174,12 @@ jobs:
153174
# Check All Tests
154175
all-tests:
155176
needs:
156-
- megatron-unit-tests
157-
- flagscale-unit-tests
158-
- functional-tests-train
159-
- functional-tests-hetero
160-
- functional-tests-inference
177+
- unit_tests_train_megatron
178+
- unit_tests_train_flagscale
179+
- unit_tests_inference_flagscale
180+
- functional_tests_train
181+
- functional_tests_hetero
182+
- functional_tests_inference
161183
- functional-tests-serve
162184
- functional-tests-rl
163185
runs-on: ubuntu-latest

.github/workflows/unit-tests-nvidia.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ jobs:
5353
pip install gitpython # TODO: Remove after updating the image
5454
5555
git config --global --add safe.directory /__w/FlagScale/FlagScale
56-
if [ "${{ inputs.backend }}" = "megatron" ] || [ "${{ inputs.backend }}" = "flagscale" ]; then
56+
if [ "${{ inputs.backend }}" = "train_megatron" ] || [ "${{ inputs.backend }}" = "train_flagscale" ]; then
5757
echo ""
5858
# PYTHONPATH=./:$PYTHONPATH pip install . --config-settings=backend="Megatron-LM" --verbose --no-build-isolation
59-
elif [ "${{ inputs.backend }}" = "vllm" ]; then
59+
elif [ "${{ inputs.backend }}" = "vllm" ] || [ "${{ inputs.backend }}" = "inference_flagscale" ]; then
6060
source /root/miniconda3/bin/activate flagscale-inference
6161
pip install scikit-build scikit-build-core
6262
pip install --no-build-isolation git+https://github.com/FlagOpen/FlagGems.git@release_v1.0.0

examples/cloud/conf/serve.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ experiment:
99
type: serve
1010
runner:
1111
type: cloud
12-
hostfile: ${oc.env:HOSTFILE, /etc/hostfile}
13-
master_addr: ${oc.env:MASTER_ADDR, 127.0.0.1}
14-
master_port: 7396
12+
nnodes: ${oc.env:LWS_GROUP_SIZE, 1}
13+
master_addr: ${oc.env:LWS_LEADER_ADDRESS, 127.0.0.1}
14+
master_port: ${oc.env:MASTER_PORT, 7396}
1515
device_type: ${oc.env:DEVICE_TYPE, gpu}
1616
nproc_per_node: ${oc.env:AIRS_ACCELERATOR_NUM, 1}
1717
deploy:

examples/cloud/conf/serve/cloud_model.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- serve_id: vllm_model
22
engine: vllm
33
engine_args:
4-
model: null
4+
model: /models/Qwen2.5-0.5B-Instruct
55
port: 8000
66
host: 0.0.0.0
77
served_model_name: cloud
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
defaults:
2+
- _self_
3+
- inference: t2i
4+
5+
experiment:
6+
exp_name: openjourney
7+
exp_dir: outputs/${experiment.exp_name}
8+
model: prompthero/openjourney
9+
task:
10+
type: inference
11+
backend: vllm # TODO(yupu): Remove this restriction
12+
entrypoint: flagscale/inference/diffusion_entrypoint.py
13+
runner:
14+
hostfile: null
15+
cmds:
16+
before_start: source /root/miniconda3/bin/activate flagscale-inference
17+
envs:
18+
CUDA_VISIBLE_DEVICES: 0
19+
CUDA_DEVICE_MAX_CONNECTIONS: 1
20+
# Optionally, set HF_HOME and HF_ENDPOINT
21+
22+
action: run
23+
24+
hydra:
25+
run:
26+
dir: ${experiment.exp_dir}/hydra
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
engine:
2+
model_config:
3+
model: ${experiment.model}
4+
loader: diffusers
5+
engine_config:
6+
results_path: ${experiment.exp_dir}/results
7+
transformations:
8+
LogIOTransformation:
9+
log_level: "info"
10+
StateScopeTransformation:
11+
{}
12+
13+
generate:
14+
prompt: "retro serie of different cars with different colors and shapes, mdjrny-v4 style"
15+
width: 512
16+
height: 512
17+
num_inference_steps: 50
18+
guidance_scale: 7.0

flagscale/backends/Megatron-LM/examples/multimodal/mlp_converter.py

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
diff --git a/examples/multimodal/mlp_converter.py b/examples/multimodal/mlp_converter.py
2+
new file mode 100644
3+
index 00000000..b105b93d
4+
--- /dev/null
5+
+++ b/examples/multimodal/mlp_converter.py
6+
@@ -0,0 +1,75 @@
7+
+# Copyright (c) 2024, FlagScale CORPORATION. All rights reserved.
8+
+import argparse
9+
+import os
10+
+
11+
+import torch
12+
+
13+
+
14+
+def convert(input_path, output_path, tensor_parallel_size):
15+
+ device = "cuda"
16+
+
17+
+ state_dict = torch.load(input_path, weights_only=False)
18+
+
19+
+ new_state_dicts = [{"model": dict()} for _ in range(tensor_parallel_size)]
20+
+
21+
+ for name, tensor in state_dict.items():
22+
+
23+
+ # Map parameter names to ones used in megatron.
24+
+ new_name = ""
25+
+ new_tensor = tensor
26+
+ chunk_dim = None
27+
+
28+
+ # This is used for chunking some tensors to target tensor parallel size.
29+
+ if name == "model.mm_projector.0.weight":
30+
+ new_name = "encoder.linear_fc1.weight"
31+
+ chunk_dim = 0
32+
+ elif name == "model.mm_projector.0.bias":
33+
+ new_name = "encoder.linear_fc1.bias"
34+
+ chunk_dim = 0
35+
+ elif name == "model.mm_projector.2.weight":
36+
+ new_name = "encoder.linear_fc2.weight"
37+
+ chunk_dim = 1
38+
+ elif name == "model.mm_projector.2.bias":
39+
+ new_name = "encoder.linear_fc2.bias"
40+
+
41+
+ assert new_name != "", f"unexpected name {name}"
42+
+
43+
+ if chunk_dim is None:
44+
+ new_tensors = [new_tensor for _ in range(tensor_parallel_size)]
45+
+ else:
46+
+ new_tensors = torch.chunk(new_tensor, tensor_parallel_size, dim=chunk_dim)
47+
+
48+
+ for i in range(tensor_parallel_size):
49+
+ # chunk() creates a view of a bigger tensor. clone() is used here to avoid excessive storage.
50+
+ new_state_dicts[i]["model"][new_name] = new_tensors[i].clone()
51+
+
52+
+ for i in range(tensor_parallel_size):
53+
+ output_path_tp = os.path.join(output_path, f"state_dict_tp_{i}.pt")
54+
+ torch.save(new_state_dicts[i], output_path_tp)
55+
+
56+
+
57+
+if __name__ == "__main__":
58+
+ parser = argparse.ArgumentParser(
59+
+ description="""
60+
+Convert LLaVA MLP weights to megatron format.
61+
+
62+
+
63+
+Example usage:
64+
+python mlp_converter.py --input /some/input/folder/mm_projector.bin --output /some/output/folder --tensor-parallel-size 2
65+
+""",
66+
+ formatter_class=argparse.RawDescriptionHelpFormatter,
67+
+ )
68+
+
69+
+ parser.add_argument("--input", type=str, required=True, help="The mlp weights with hf format")
70+
+ parser.add_argument(
71+
+ "--output", type=str, required=True, help="output directory for megatron state dict file(s)"
72+
+ )
73+
+ parser.add_argument(
74+
+ "--tensor-parallel-size", type=int, default=1, help="model tensor parallel size"
75+
+ )
76+
+
77+
+ args = parser.parse_args()
78+
+
79+
+ convert(args.input, args.output, args.tensor_parallel_size)
80+
+
81+
+ print("done.")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
diff --git a/megatron/__init__.py b/megatron/__init__.py
2+
new file mode 100644
3+
index 00000000..e69de29b

0 commit comments

Comments
 (0)