@@ -264,7 +264,9 @@ def __custom_line_sampler(*args, **kwargs):
264264max_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
398407if 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
506515program_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 (
0 commit comments