@@ -14,10 +14,11 @@ plugins {
1414// Model files configuration for instrumentation tests
1515val modelFilesBaseUrl = " https://ossci-android.s3.amazonaws.com/executorch/stories/snapshot-20260114"
1616val deviceModelDir = " /data/local/tmp/llama"
17- val modelFiles = listOf (
18- " stories110M.pte" ,
19- " tokenizer.model"
17+ val modelFiles = mapOf (
18+ " stories110M.pte" to " model.pte " ,
19+ " tokenizer.model" to " tokenizer.model "
2020)
21+ val skipModelDownload: Boolean = (project.findProperty(" skipModelDownload" ) as ? String )?.toBoolean() ? : false
2122
2223fun execCmd (vararg args : String ): String {
2324 val process = ProcessBuilder (* args)
@@ -42,6 +43,11 @@ tasks.register("pushModelFiles") {
4243 group = " verification"
4344
4445 doLast {
46+ if (skipModelDownload) {
47+ logger.lifecycle(" Skipping model download (skipModelDownload=true)" )
48+ return @doLast
49+ }
50+
4551 // Check if adb is available
4652 val adbPath = android.adbExecutable.absolutePath
4753 val (adbCheckCode, _) = execCmdWithExitCode(adbPath, " devices" )
@@ -50,8 +56,8 @@ tasks.register("pushModelFiles") {
5056 }
5157
5258 // Check which files need to be pushed
53- val filesToPush = modelFiles.filter { fileName ->
54- val devicePath = " $deviceModelDir /$fileName "
59+ val filesToPush = modelFiles.filter { (_, targetName) ->
60+ val devicePath = " $deviceModelDir /$targetName "
5561 val (exitCode, _) = execCmdWithExitCode(adbPath, " shell" , " test -f $devicePath && echo exists" )
5662 exitCode != 0
5763 }
@@ -61,7 +67,7 @@ tasks.register("pushModelFiles") {
6167 return @doLast
6268 }
6369
64- logger.lifecycle(" Need to push ${filesToPush.size} model file(s): ${filesToPush.joinToString(" , " )} " )
70+ logger.lifecycle(" Need to push ${filesToPush.size} model file(s): ${filesToPush.values. joinToString(" , " )} " )
6571
6672 // Create temp directory using mktemp
6773 val tempDir = execCmd(" mktemp" , " -d" )
@@ -71,45 +77,52 @@ tasks.register("pushModelFiles") {
7177 // Create device directory
7278 execCmd(adbPath, " shell" , " mkdir -p $deviceModelDir " )
7379
74- for (fileName in filesToPush) {
75- val localPath = " $tempDir /$fileName "
76- val checksumPath = " $tempDir /$fileName .sha256sums"
77- val devicePath = " $deviceModelDir /$fileName "
80+ for ((sourceName, targetName) in filesToPush) {
81+ val localPath = " $tempDir /$targetName "
82+ val checksumPath = " $tempDir /$sourceName .sha256sums"
83+ val devicePath = " $deviceModelDir /$targetName "
7884
79- // Download file
80- logger.lifecycle(" Downloading $fileName ..." )
85+ // Download file (with original name for checksum verification, then rename)
86+ val downloadPath = " $tempDir /$sourceName "
87+ logger.lifecycle(" Downloading $sourceName ..." )
8188 val (dlCode, dlOutput) = execCmdWithExitCode(
82- " curl" , " -fL" , " -o" , localPath , " $modelFilesBaseUrl /$fileName "
89+ " curl" , " -fL" , " -o" , downloadPath , " $modelFilesBaseUrl /$sourceName "
8390 )
8491 if (dlCode != 0 ) {
85- throw GradleException (" Failed to download $fileName : $dlOutput " )
92+ throw GradleException (" Failed to download $sourceName : $dlOutput " )
8693 }
8794
8895 // Download and verify checksum
89- logger.lifecycle(" Verifying checksum for $fileName ..." )
96+ logger.lifecycle(" Verifying checksum for $sourceName ..." )
9097 val (csDownloadCode, csDownloadOutput) = execCmdWithExitCode(
91- " curl" , " -fL" , " -o" , checksumPath, " $modelFilesBaseUrl /$fileName .sha256sums"
98+ " curl" , " -fL" , " -o" , checksumPath, " $modelFilesBaseUrl /$sourceName .sha256sums"
9299 )
93100 if (csDownloadCode != 0 ) {
94- throw GradleException (" Failed to download checksum for $fileName : $csDownloadOutput " )
101+ throw GradleException (" Failed to download checksum for $sourceName : $csDownloadOutput " )
95102 }
96103
97104 // Verify checksum (run sha256sum in the temp directory)
98105 val (verifyCode, verifyOutput) = execCmdWithExitCode(
99- " bash" , " -c" , " cd $tempDir && sha256sum -c $fileName .sha256sums"
106+ " bash" , " -c" , " cd $tempDir && sha256sum -c $sourceName .sha256sums"
100107 )
101108 if (verifyCode != 0 ) {
102- throw GradleException (" Checksum verification failed for $fileName : $verifyOutput " )
109+ throw GradleException (" Checksum verification failed for $sourceName : $verifyOutput " )
110+ }
111+ logger.lifecycle(" Checksum verified for $sourceName " )
112+
113+ // Rename file if needed
114+ if (sourceName != targetName) {
115+ execCmd(" mv" , downloadPath, localPath)
116+ logger.lifecycle(" Renamed $sourceName to $targetName " )
103117 }
104- logger.lifecycle(" Checksum verified for $fileName " )
105118
106119 // Push to device
107- logger.lifecycle(" Pushing $fileName to device..." )
120+ logger.lifecycle(" Pushing $targetName to device..." )
108121 val (pushCode, pushOutput) = execCmdWithExitCode(adbPath, " push" , localPath, devicePath)
109122 if (pushCode != 0 ) {
110- throw GradleException (" Failed to push $fileName to device: $pushOutput " )
123+ throw GradleException (" Failed to push $targetName to device: $pushOutput " )
111124 }
112- logger.lifecycle(" Successfully pushed $fileName " )
125+ logger.lifecycle(" Successfully pushed $targetName " )
113126 }
114127 } finally {
115128 // Clean up temp directory
0 commit comments