Skip to content

Commit

Permalink
Use seconds instead of milliseconds for latency metrics.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 687349834
  • Loading branch information
yishuangP authored and copybara-github committed Oct 18, 2024
1 parent f892e20 commit a460350
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension LlmInference {
} ?? llmInference.createSessionRunner(sessionConfig: sessionConfig)

self.llmInference = llmInference
self.metrics = Metrics(responseGenerationTimeInMillis: 0)
self.metrics = Metrics(responseGenerationTimeInSeconds: 0)
super.init()
}

Expand Down Expand Up @@ -97,7 +97,7 @@ extension LlmInference {
init(llmSessionRunner: LlmSessionRunner, llmInference: LlmInference) {
self.llmSessionRunner = llmSessionRunner
self.llmInference = llmInference
self.metrics = Metrics(responseGenerationTimeInMillis: 0)
self.metrics = Metrics(responseGenerationTimeInSeconds: 0)
super.init()
}

Expand Down Expand Up @@ -256,9 +256,8 @@ extension LlmInference {
private func markResponseGenerationCompleted() {
llmInference.markResponseGenerationCompleted()
metrics = Metrics(
responseGenerationTimeInMillis: (TimeInterval(clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW))
- responseGenerationStartTime) * 1000
/ TimeInterval(NSEC_PER_SEC))
responseGenerationTimeInSeconds: (TimeInterval(clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW))
- responseGenerationStartTime) / TimeInterval(NSEC_PER_SEC))
}

private static func humanReadableString(
Expand Down Expand Up @@ -310,13 +309,11 @@ extension LlmInference.Session {
/// Note: Inherits from `NSObject` for Objective C interoperability.
@objc(MPPLLMInferenceSessionMetrics) public final class Metrics: NSObject {

/// The time it took to generate the full response for last query, in milliseconds.
@objc public private(set) var responseGenerationTimeInMillis: TimeInterval
/// The time it took to generate the full response for last query, in seconds.
@objc public private(set) var responseGenerationTimeInSeconds: TimeInterval

@objc public init(
responseGenerationTimeInMillis: TimeInterval
) {
self.responseGenerationTimeInMillis = responseGenerationTimeInMillis
@objc public init(responseGenerationTimeInSeconds: TimeInterval) {
self.responseGenerationTimeInSeconds = responseGenerationTimeInSeconds
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions mediapipe/tasks/ios/genai/inference/sources/LlmInference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import MediaPipeTasksGenAIC
}
let timeAfterInit = clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW)
metrics = Metrics(
initializationTimeInMillis: (TimeInterval(timeAfterInit - timeBeforeInit) * 1000)
initializationTimeInSeconds: TimeInterval(timeAfterInit - timeBeforeInit)
/ TimeInterval(NSEC_PER_SEC))

super.init()
Expand Down Expand Up @@ -256,13 +256,13 @@ extension LlmInference {
///
/// Note: Inherits from `NSObject` for Objective C interoperability.
@objc(MPPLLMInferenceMetrics) public final class Metrics: NSObject {
/// The time it took to initialize the LLM inference engine, in milliseconds.
/// The time it took to initialize the LLM inference engine, in seconds.
/// If you want to include the time it took to load the model weights, set
/// `LlmInference.Options.waitForWeightUploads` to true.
@objc public private(set) var initializationTimeInMillis: TimeInterval
@objc public let initializationTimeInSeconds: TimeInterval

@objc public init(initializationTimeInMillis: TimeInterval) {
self.initializationTimeInMillis = initializationTimeInMillis
@objc public init(initializationTimeInSeconds: TimeInterval) {
self.initializationTimeInSeconds = initializationTimeInSeconds
}
}
}

0 comments on commit a460350

Please sign in to comment.