-
Notifications
You must be signed in to change notification settings - Fork 607
Define generic Android benchmark metric structure #5332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
27c895d
Define generic Android benchmark metric structure
huydhn 57c3c5e
Parse the model name for backend and quantization
huydhn 5c5499a
Keep model and Android version
huydhn 0488a12
Address review comments
huydhn 60800bd
Merge branch 'main' into android-benchmark-json-output
huydhn a529c3b
Move Android OS version to a separate field
huydhn b2b117e
Use nano second
huydhn a66b834
Add memory info
huydhn 2ea88c4
Init DeviceInfo
huydhn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
extension/android/benchmark/app/src/main/java/org/pytorch/minibench/BenchmarkMetric.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package org.pytorch.minibench; | ||
|
||
import android.app.ActivityManager; | ||
import android.os.Build; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
class BenchmarkMetric { | ||
public static class BenchmarkModel { | ||
// The model name, i.e. stories110M | ||
String name; | ||
String backend; | ||
String quantization; | ||
|
||
public BenchmarkModel(final String name, final String backend, final String quantization) { | ||
this.name = name; | ||
this.backend = backend; | ||
this.quantization = quantization; | ||
} | ||
} | ||
|
||
BenchmarkModel benchmarkModel; | ||
|
||
// The metric name, i.e. TPS | ||
String metric; | ||
|
||
// The actual value and the option target value | ||
double actualValue; | ||
double targetValue; | ||
|
||
public static class DeviceInfo { | ||
// Let's see which information we want to include here | ||
final String device = Build.BRAND; | ||
// The phone model and Android release version | ||
final String arch = Build.MODEL; | ||
final String os = "Android " + Build.VERSION.RELEASE; | ||
final long totalMem = new ActivityManager.MemoryInfo().totalMem; | ||
final long availMem = new ActivityManager.MemoryInfo().availMem; | ||
} | ||
|
||
DeviceInfo deviceInfo = new DeviceInfo(); | ||
|
||
public BenchmarkMetric( | ||
final BenchmarkModel benchmarkModel, | ||
final String metric, | ||
final double actualValue, | ||
final double targetValue) { | ||
this.benchmarkModel = benchmarkModel; | ||
this.metric = metric; | ||
this.actualValue = actualValue; | ||
this.targetValue = targetValue; | ||
} | ||
|
||
// TODO (huydhn): Figure out a way to extract the backend and quantization information from | ||
// the .pte model itself instead of parsing its name | ||
public static BenchmarkMetric.BenchmarkModel extractBackendAndQuantization(final String model) { | ||
final Matcher m = | ||
Pattern.compile("(?<name>\\w+)_(?<backend>\\w+)_(?<quantization>\\w+)").matcher(model); | ||
if (m.matches()) { | ||
return new BenchmarkMetric.BenchmarkModel( | ||
m.group("name"), m.group("backend"), m.group("quantization")); | ||
} else { | ||
return new BenchmarkMetric.BenchmarkModel(model, "", ""); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably log the time for module.loadMethod() before first forward() 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, let me try to copy it from llama and add one here too