Skip to content
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

Enable Sequence Packing and Pipeline Parallel in NeVA #8957

Merged
merged 34 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f2f267d
temp save
yaoyu-33 Mar 16, 2024
b532d1b
Merge branch 'main' into yuya/neva_seq_pack
yaoyu-33 Mar 18, 2024
b0ace6b
temp save 2
yaoyu-33 Mar 18, 2024
0020fe3
update code
yaoyu-33 Mar 19, 2024
76fb748
Merge branch 'main' into yuya/neva_seq_pack
yaoyu-33 Mar 19, 2024
a8f2248
enable seq packing
yaoyu-33 Mar 19, 2024
9fab5a5
fix neva and clip
yaoyu-33 Mar 18, 2024
d8474fb
Enable parallel seq packing algo and few other fixes
yaoyu-33 Mar 21, 2024
c56ec9b
Merge branch 'main' into yuya/neva_seq_pack
yaoyu-33 Mar 22, 2024
e8a9a6d
Pipeline parallel support
yaoyu-33 Mar 25, 2024
c5ffa83
Update data preprocess
yaoyu-33 Mar 25, 2024
e11e260
Merge branch 'main' into yuya/neva_pp_support
yaoyu-33 Apr 2, 2024
2bc5d66
fix few pp issues
yaoyu-33 Apr 2, 2024
4843e54
Merge branch 'yuya/neva_seq_pack' into yuya/neva_pp_support
yaoyu-33 Apr 4, 2024
78034ce
enable sequence packing w/ PP
yaoyu-33 Apr 4, 2024
8561e60
Fix cu_seqlens in inputs
yaoyu-33 Apr 5, 2024
2ac6b27
add assert
yaoyu-33 Apr 8, 2024
d138b1e
Merge branch 'main' into yuya/neva_pp_support
yaoyu-33 Apr 16, 2024
5e6994d
Depend on PP to decide whether do padding
yaoyu-33 Apr 17, 2024
0544758
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 17, 2024
6af32af
Add docstring
yaoyu-33 Apr 17, 2024
cd513b3
Merge remote-tracking branch 'origin/yuya/neva_pp_support' into yuya/…
yaoyu-33 Apr 17, 2024
3655f7d
Fix few evaluation issues
yaoyu-33 Apr 23, 2024
f54e565
Merge branch 'main' into yuya/neva_pp_support
yaoyu-33 Apr 24, 2024
4bb0313
Fix few PP evaluation issues
yaoyu-33 Apr 24, 2024
6efa4fa
Address comments
yaoyu-33 Apr 24, 2024
9c44e30
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 24, 2024
56700e7
address comments
yaoyu-33 Apr 25, 2024
b5a4c27
Fix license
yaoyu-33 Apr 26, 2024
f2588a0
Merge branch 'main' into yuya/neva_pp_support
yaoyu-33 Apr 26, 2024
45a6c61
Merge branch 'main' into yuya/neva_pp_support
yaoyu-33 Apr 29, 2024
8d9f8c1
Few neva bugs
yaoyu-33 Apr 30, 2024
449a42f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 30, 2024
0380c3b
Few neva bugs
yaoyu-33 Apr 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ model:
additional_special_tokens: null # ["<extra_id_0>", "<extra_id_1>", "<extra_id_2>", "<extra_id_3>", "<extra_id_4>", "<extra_id_5>"]

data:
packed_sequence: False
num_workers: 8
dataloader_type: cyclic
data_path:
Expand Down
42 changes: 24 additions & 18 deletions examples/multimodal/multimodal_llm/neva/eval/vqa_science.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def eval_model(args):
cfg.base_model_file = args.model_base
cfg.inference.images_base_path = args.image_folder
cfg.tensor_model_parallel_size = args.tp
cfg.trainer.devices = args.tp
cfg.pipeline_model_parallel_size = args.pp
cfg.trainer.devices = args.tp * args.pp

model, image_processor = create_neva_model_and_processor(cfg)
length_params: LengthParam = {
Expand All @@ -102,7 +103,8 @@ def eval_model(args):
questions = get_chunk(questions, args.num_chunks, args.chunk_idx)
answers_file = os.path.expanduser(args.answers_file)
os.makedirs(os.path.dirname(answers_file), exist_ok=True)
ans_file = open(answers_file, "w")
if is_global_rank_zero():
ans_file = open(answers_file, "w")
Dismissed Show dismissed Hide dismissed
for i, line in enumerate(tqdm(questions, disable=(not is_global_rank_zero()))):
idx = line["id"]
question = line['conversations'][0]
Expand All @@ -123,7 +125,8 @@ def eval_model(args):
sampling_params=sampling_params,
inference_config=cfg,
)
# import pdb; pdb.set_trace()
if responses is None:
continue
outputs = responses[0]["clean_response"]

# prompt for answer
Expand All @@ -139,22 +142,24 @@ def eval_model(args):
outputs = responses[0]["clean_response"]
outputs = outputs_reasoning + '\n The answer is ' + outputs

ans_id = shortuuid.uuid()
ans_file.write(
json.dumps(
{
"question_id": idx,
"prompt": cur_prompt,
"text": outputs,
"answer_id": ans_id,
"model_id": args.model_path,
"metadata": {},
}
if is_global_rank_zero():
ans_id = shortuuid.uuid()
ans_file.write(
json.dumps(
{
"question_id": idx,
"prompt": cur_prompt,
"text": outputs,
"answer_id": ans_id,
"model_id": args.model_path,
"metadata": {},
}
)
+ "\n"
)
+ "\n"
)
ans_file.flush()
ans_file.close()
ans_file.flush()
if is_global_rank_zero():
ans_file.close()


if __name__ == "__main__":
Expand All @@ -166,6 +171,7 @@ def eval_model(args):
parser.add_argument("--answers-file", type=str, default="answer.jsonl")
parser.add_argument("--conv-mode", type=str, default="llava_v0")
parser.add_argument("--tp", type=int, default=1)
parser.add_argument("--pp", type=int, default=1)
parser.add_argument("--num-chunks", type=int, default=1)
parser.add_argument("--chunk-idx", type=int, default=0)
parser.add_argument("--temperature", type=float, default=0.2)
Expand Down
38 changes: 22 additions & 16 deletions examples/multimodal/multimodal_llm/neva/neva_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from nemo.collections.multimodal.parts.utils import create_neva_model_and_processor
from nemo.collections.nlp.modules.common.transformer.text_generation import LengthParam, SamplingParam
from nemo.core.config import hydra_runner
from nemo.utils.get_rank import is_global_rank_zero


try:
Expand Down Expand Up @@ -121,22 +122,27 @@ def forward_loop():
)
# ============== Quantization End =========================

results = []
for response, prompt in zip(responses, final_prompts):
prompt['full_text'] = response["clean_text"]
prompt['text'] = response["clean_response"]
prompt['model_id'] = cfg.neva_model_file
if 'image_path' in prompt:
prompt['image'] = prompt.pop('image_path')
if 'answer_id' not in prompt:
prompt['answer_id'] = 0
if 'metadata' not in prompt:
prompt['metadata'] = {}
results.append(prompt)

with open(cfg.output_file, 'w') as f:
for result in results:
f.write(json.dumps(result) + '\n')
# PP middle stages do not yield any responses
if responses is None:
return

if is_global_rank_zero():
results = []
for response, prompt in zip(responses, final_prompts):
prompt['full_text'] = response["clean_text"]
prompt['text'] = response["clean_response"]
prompt['model_id'] = cfg.neva_model_file
if 'image_path' in prompt:
prompt['image'] = prompt.pop('image_path')
if 'answer_id' not in prompt:
prompt['answer_id'] = 0
if 'metadata' not in prompt:
prompt['metadata'] = {}
results.append(prompt)

with open(cfg.output_file, 'w') as f:
for result in results:
f.write(json.dumps(result) + '\n')


if __name__ == '__main__':
Expand Down
Loading
Loading