@@ -31,6 +31,7 @@ import {
31
31
} from "../../../../utils/time" ;
32
32
import { BenchmarkingLogger } from "../../logging/benchmarkingLogger" ;
33
33
import { writeTeamCityStatisticsValue } from "../../logging/consoleWriteUtils" ;
34
+ import { infinitySymbol } from "../../logging/specialSymbols" ;
34
35
import { BenchmarkingModelParams } from "../../structures/benchmarkingCore/benchmarkingModelParams" ;
35
36
import { BenchmarkingOptions } from "../../structures/benchmarkingCore/benchmarkingOptions" ;
36
37
import {
@@ -129,15 +130,6 @@ export async function benchmarkSingleCompletionGeneration<
129
130
logger ,
130
131
abortSignal
131
132
) ;
132
- logger
133
- . asOneRecord ( )
134
- . info (
135
- `Successfully generated ${ proofGenerationResult . generatedProofs . length } proof(s)`
136
- )
137
- . debug (
138
- `Effective elapsed time: ${ proofGenerationResult . effectiveElapsedTimeMillis } ms` ,
139
- "gray"
140
- ) ;
141
133
const preparedProofs : [ string , GeneratedProof , number ] [ ] =
142
134
proofGenerationResult . generatedProofs . map (
143
135
( generatedProof : GeneratedProof , index : number ) => [
@@ -266,6 +258,12 @@ export async function benchmarkSingleCompletionGeneration<
266
258
return result ;
267
259
}
268
260
261
+ /**
262
+ * Prevents from buggy delay estimates:
263
+ * infinite cycle with zero delays might cause some troubles.
264
+ */
265
+ export const minDelayMillis = 100 ;
266
+
269
267
namespace RemoteConnectionErrorDelays {
270
268
export const initialDelayMillis = 10_000 ;
271
269
export const exponentialMultiplier = 2 ;
@@ -341,6 +339,7 @@ async function generateProofWithRetriesExclusively<
341
339
generateProof ,
342
340
generationArgs . llmService ,
343
341
options ,
342
+ generationArgs . roundNumber ,
344
343
logger ,
345
344
abortSignal
346
345
) ;
@@ -353,19 +352,29 @@ async function generateProofWithRetriesMeasured(
353
352
) => Promise < GeneratedProof [ ] > ,
354
353
llmService : LLMService < any , any > ,
355
354
options : BenchmarkingOptions ,
355
+ roundNumber : number ,
356
356
logger : BenchmarkingLogger ,
357
357
abortSignal : AbortSignal
358
358
) : Promise < ProofGenerationResult > {
359
359
let delayMillis = 0 ;
360
360
let prevFailureIsConnectionError = false ;
361
- let attemptIndex = 0 ;
361
+ let attemptIndex = 1 ;
362
+ const maxAttemptsString = options . proofGenerationRetries ?? infinitySymbol ;
362
363
363
364
let totalTime = new TimeMark ( ) ;
364
365
while ( true ) {
366
+ const attemptLogger = logger . createChildLoggerWithIdentifier (
367
+ `[proof generation attempt ${ attemptIndex } /${ maxAttemptsString } ]`
368
+ ) ;
365
369
// `options.proofGenerationRetries` might be undefined meaning the unlimited retries case
366
- if ( attemptIndex === options . proofGenerationRetries ) {
370
+ if ( attemptIndex - 1 === options . proofGenerationRetries ) {
371
+ attemptLogger . error (
372
+ `max retries (${ options . proofGenerationRetries } ) has been reached` ,
373
+ "default"
374
+ ) ;
367
375
throwBenchmarkingError (
368
- `Proof generation failed: max retries (${ options . proofGenerationRetries } ) has been reached`
376
+ `Proof generation failed: max retries (${ options . proofGenerationRetries } ) ` ,
377
+ `has been reached at round ${ roundNumber } `
369
378
) ;
370
379
}
371
380
throwOnAbort ( abortSignal ) ;
@@ -386,10 +395,10 @@ async function generateProofWithRetriesMeasured(
386
395
} ;
387
396
388
397
const tokens = result . tokensSpentInTotal ;
389
- logger
398
+ attemptLogger
390
399
. asOneRecord ( )
391
- . debug (
392
- `Attempt # ${ attemptIndex } , successfully generated proofs `
400
+ . info (
401
+ `Successfully generated ${ generatedProofs . length } proof(s) `
393
402
)
394
403
. debug (
395
404
`Tokens spent: ${ tokens . tokensSpentInTotal } = ${ tokens . promptTokens } (prompt) + ${ tokens . generatedTokens } (generated answer)`
@@ -415,19 +424,23 @@ async function generateProofWithRetriesMeasured(
415
424
const llmServiceError = e as LLMServiceError ;
416
425
417
426
if ( llmServiceError instanceof ConfigurationError ) {
418
- logger . debug (
419
- `Attempt #${ attemptIndex } , configuration error: ${ llmServiceError . message } `
427
+ attemptLogger . error (
428
+ `Configuration error: ${ llmServiceError . message } ` ,
429
+ "default"
420
430
) ;
421
431
throw llmServiceError ;
422
432
}
423
433
if ( llmServiceError instanceof GenerationFailedError ) {
424
434
const estimatedTime =
425
435
llmService . estimateTimeToBecomeAvailable ( ) ;
426
- delayMillis = timeToMillis ( estimatedTime ) ;
427
- logger
436
+ delayMillis = Math . max (
437
+ timeToMillis ( estimatedTime ) ,
438
+ minDelayMillis
439
+ ) ;
440
+ attemptLogger
428
441
. asOneRecord ( )
429
442
. debug (
430
- `Attempt # ${ attemptIndex } , generation failed error: ${ llmServiceError . message } `
443
+ `Generation failed error: ${ llmServiceError . message } `
431
444
)
432
445
. debug (
433
446
`Estimated time to become available: ${ timeToString ( estimatedTime ) } `
@@ -441,10 +454,10 @@ async function generateProofWithRetriesMeasured(
441
454
RemoteConnectionErrorDelays . initialDelayMillis ;
442
455
prevFailureIsConnectionError = true ;
443
456
}
444
- logger
457
+ attemptLogger
445
458
. asOneRecord ( )
446
459
. debug (
447
- `Attempt # ${ attemptIndex } , remote connection error: ${ stringifyAnyValue ( llmServiceError . message ) } `
460
+ `Remote connection error: ${ stringifyAnyValue ( llmServiceError . message ) } `
448
461
)
449
462
. debug ( `Delay to wait for: ${ millisToString ( delayMillis ) } ` ) ;
450
463
} else {
0 commit comments