Skip to content

Commit 838d14d

Browse files
authored
Merge pull request #160 from foundation-model-stack/chunked_padding
Add padding to chunk size and update env vars
2 parents 5e84730 + b541d7a commit 838d14d

2 files changed

Lines changed: 39 additions & 10 deletions

File tree

aiu_fms_testing_utils/scripts/drive_paged_programs.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ def __custom_line_sampler(*args, **kwargs):
264264
max_tkv = int(os.environ["VLLM_DT_MAX_CONTEXT_LEN"])
265265

266266

267-
def __prepare_inputs(batch_size, seq_length, tokenizer, enforce_sizes=[], seed=0):
267+
def __prepare_inputs(
268+
batch_size, seq_length, tokenizer, enforce_sizes=[], seed=0, pad_multiple=64
269+
):
268270
start = time.time()
269271
prompts_and_sizes, sample_key = sampler(
270272
DATASET_PATH,
@@ -276,6 +278,7 @@ def __prepare_inputs(batch_size, seq_length, tokenizer, enforce_sizes=[], seed=0
276278
enforce_sizes=enforce_sizes,
277279
truncation=allow_truncation,
278280
return_key=True,
281+
pad_multiple=pad_multiple,
279282
)
280283
end = time.time()
281284
if local_rank == 0:
@@ -393,7 +396,13 @@ def __load_validation_info(
393396
# warmup with any input so compiler produces criteria json
394397
# TODO: Swap this with __prepare_inputs once fix for shape_id is available
395398
# input_ids, extra_kwargs, sample_key = __prepare_inputs(2, max_tkv, tokenizer)
396-
prompt_list = [torch.arange(0, 64, dtype=torch.int64)]
399+
pad_multiple = 64
400+
if args.prefill_chunk_size > 0:
401+
assert args.prefill_chunk_size % 64 == 0, (
402+
"Chunk size must be a multiple of the page size"
403+
)
404+
pad_multiple = args.prefill_chunk_size
405+
prompt_list = [torch.arange(0, pad_multiple, dtype=torch.int64)]
397406
# matching vllm warmup to pad to 2 on fp8, and no pad for fp16
398407
if is_fp8:
399408
prompt_list = prompt_list * 2
@@ -505,7 +514,7 @@ def parse_program_limit(limit_str: str) -> tuple[int, str]:
505514
# FIXME: filter condition for this on prompt and batch
506515
program_map = get_programs_prompts(
507516
program_criteria_list,
508-
multiple=64,
517+
multiple=pad_multiple,
509518
max_batch_size=max_batch_size,
510519
max_tkv=max_tkv,
511520
program_cycles=max_new_tokens,
@@ -526,6 +535,7 @@ def parse_program_limit(limit_str: str) -> tuple[int, str]:
526535
valid_prompt_shape[1],
527536
tokenizer,
528537
enforce_sizes=enforce_sizes,
538+
pad_multiple=pad_multiple,
529539
)
530540
valid_prompts = [
531541
(
@@ -579,14 +589,29 @@ def parse_program_limit(limit_str: str) -> tuple[int, str]:
579589
# if there does not exist enough sequence sizes between this range, we will cycle back to the beginning
580590
# in the event we don't have enough sequences that satisfy the enforce_sizes, we will repeat sequences and warn the user
581591
enforce_sizes = [valid_prompt_shape[1]]
582-
if args.enforce_homogeneous_prompt_programs:
583-
# this will get the number of bits for the sequence length and shift to get the power of 2 that is less than or equal to the sequence length
584-
tkv_cutoff = 1 << (valid_prompt_shape[1].bit_length() - 1)
592+
if (
593+
args.enforce_homogeneous_prompt_programs
594+
or args.prefill_chunk_size > 0
595+
):
596+
# if enforcing homogeneous prompt programs, this will get the number of bits for the sequence length and shift to get the power of 2 that is less than or equal to the sequence length
597+
tkv_cutoff = (
598+
1 << (valid_prompt_shape[1].bit_length() - 1)
599+
if args.enforce_homogeneous_prompt_programs
600+
else pad_multiple
601+
)
602+
585603
possible_seq_lengths = [
586-
_ for _ in range(tkv_cutoff, valid_prompt_shape[1], 64)
604+
_
605+
for _ in range(
606+
tkv_cutoff, valid_prompt_shape[1], pad_multiple
607+
)
587608
]
588609
# favor sequences that are close to the valid prompt length
589610
possible_seq_lengths.reverse()
611+
# add the valid prompt size to the end since it will already exist in the above enforce_sizes
612+
possible_seq_lengths = possible_seq_lengths + [
613+
valid_prompt_shape[1]
614+
]
590615
enforce_sizes = enforce_sizes + list(
591616
itertools.islice(
592617
itertools.cycle(possible_seq_lengths),
@@ -599,6 +624,7 @@ def parse_program_limit(limit_str: str) -> tuple[int, str]:
599624
valid_prompt_shape[1],
600625
tokenizer,
601626
enforce_sizes=enforce_sizes,
627+
pad_multiple=64, # this should be the smallest granularity to ensure we get the largest enforce_size (if we choose chunked prefill, we want to make sure we pad to the full enforced size)
602628
)
603629
valid_prompts.append(
604630
(

aiu_fms_testing_utils/utils/paged.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ def generate(
316316
.unsqueeze(0)
317317
.clone()
318318
)
319+
assert input_ids_seq_chunk.size(1) == prefill_chunk_size, (
320+
f"prefill chunk size was not equal to the chunk size. Found {input_ids_seq_chunk.size(0)}"
321+
)
319322
slots_length = len(slot_mapping[seq_i])
320323
slot_mapping_seq_chunk = (
321324
torch.tensor(
@@ -577,12 +580,12 @@ def generate(
577580
return result
578581

579582

580-
# this value is default to 2080 to be consistent with vllm for granite 3.3 8b instruct
583+
# this value is default to 8192 to be consistent with vllm for granite 3.3 8b instruct w/ chunked prefill
581584
KVCACHE_NUM_BLOCKS_HINT = int(
582-
os.environ.get("AFTU_PAGED_KVCACHE_NUM_BLOCKS_HINT", 2080)
585+
os.environ.get("AFTU_PAGED_KVCACHE_NUM_BLOCKS_HINT", 8192)
583586
)
584587

585-
VLLM_DT_MAX_BATCH_TKV_LIMIT = int(os.environ.get("VLLM_DT_MAX_BATCH_TKV_LIMIT", 131072))
588+
VLLM_DT_MAX_BATCH_TKV_LIMIT = int(os.environ.get("VLLM_DT_MAX_BATCH_TKV_LIMIT", 524288))
586589

587590

588591
class ProgramCriteria:

0 commit comments

Comments
 (0)