2424_MAX_INT32 = (1 << 31 ) - 1
2525
2626
27- def _validate_limits (parser , args , * , prefix_capture_slots = 0 ) -> int :
27+ def _validate_limits (
28+ parser , args , * , prefix_capture_slots = 0 , prefix_capture_prompt_end = False
29+ ) -> int :
2830 for flag , value in (
2931 ("--max-context" , args .max_context ),
3032 ("--max-sessions" , args .max_sessions ),
@@ -37,14 +39,18 @@ def _validate_limits(parser, args, *, prefix_capture_slots=0) -> int:
3739 parser .error (f"--prefix-cache-entries must be between 0 and { _MAX_INT32 } " )
3840 if not 0 <= args .prefix_checkpoint_interval <= _MAX_INT32 :
3941 parser .error (f"--prefix-checkpoint-interval must be between 0 and { _MAX_INT32 } " )
40- if args .prefix_checkpoint_interval and not args .prefix_cache_entries :
41- parser .error ("--prefix-checkpoint-interval requires --prefix-cache-entries > 0" )
42+ if (
43+ args .prefix_checkpoint_interval or prefix_capture_prompt_end
44+ ) and not args .prefix_cache_entries :
45+ parser .error (
46+ "prefix checkpoints and prompt-end capture require --prefix-cache-entries > 0"
47+ )
4248 if not 0 <= prefix_capture_slots <= _MAX_INT32 :
4349 parser .error (f"--prefix-capture-slots must be between 0 and { _MAX_INT32 } " )
4450 # Mirrors ServingRuntimeConfig::resolved_prefix_captures for row validation.
4551 if prefix_capture_slots == 0 :
4652 prefix_capture_slots = min (args .max_sessions , args .max_inflight_requests )
47- if args .prefix_checkpoint_interval :
53+ if args .prefix_checkpoint_interval or prefix_capture_prompt_end :
4854 prefix_capture_slots = min (prefix_capture_slots , 2 )
4955 if not args .prefix_cache_entries :
5056 prefix_capture_slots = 0
@@ -89,6 +95,11 @@ def _parse_args(argv=None):
8995 parser .add_argument ("--max-decode-sequences" , type = int , default = 8 )
9096 parser .add_argument ("--max-inflight-requests" , type = int , default = 64 )
9197 parser .add_argument ("--prefix-cache-entries" , type = int , default = 0 )
98+ parser .add_argument (
99+ "--prefix-capture-prompt-end" ,
100+ action = "store_true" ,
101+ help = "Retain each request's prompt end in the bounded prefix cache" ,
102+ )
92103 parser .add_argument (
93104 "--prefix-capture-slots" ,
94105 type = int ,
@@ -99,13 +110,18 @@ def _parse_args(argv=None):
99110 "--prefix-checkpoint-interval" ,
100111 type = int ,
101112 default = 0 ,
102- help = "Checkpoint interval in tokens; 0: initial prompt only. Uses global LRU ." ,
113+ help = "Periodic checkpoint interval in tokens; 0 disables periodic capture ." ,
103114 )
104115 parser .add_argument ("--host" , default = "127.0.0.1" )
105116 parser .add_argument ("--port" , type = int , default = 8000 )
106117 args = parser .parse_args (argv )
107118
108- _validate_limits (parser , args , prefix_capture_slots = args .prefix_capture_slots )
119+ _validate_limits (
120+ parser ,
121+ args ,
122+ prefix_capture_slots = args .prefix_capture_slots ,
123+ prefix_capture_prompt_end = args .prefix_capture_prompt_end ,
124+ )
109125
110126 args .worker_bin = os .path .expanduser (args .worker_bin )
111127 if shutil .which (args .worker_bin ) is None :
@@ -177,6 +193,11 @@ async def serving_factory():
177193 if args .prefix_checkpoint_interval
178194 else []
179195 )
196+ + (
197+ ["--prefix_capture_prompt_end=true" ]
198+ if args .prefix_capture_prompt_end
199+ else []
200+ )
180201 )
181202 runtime = None
182203 try :
0 commit comments