Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions llm/android/LlamaDemo/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,16 @@ android {
}

dependencies {
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
implementation("androidx.activity:activity-compose:1.7.0")
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2024.02.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
implementation("io.coil-kt:coil-compose:2.5.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.camera:camera-core:1.3.0-rc02")
implementation("androidx.constraintlayout:constraintlayout:2.2.0-alpha12")
Expand All @@ -281,7 +283,7 @@ dependencies {
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.2.0")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
androidTestImplementation(platform("androidx.compose:compose-bom:2024.02.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 com.example.executorchllamademo

import android.os.Bundle
import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.pytorch.executorch.extension.llm.LlmCallback
import org.pytorch.executorch.extension.llm.LlmModule

/**
* Sanity check test for model loading and generation.
*
* Model filenames can be configured via instrumentation arguments:
* - modelFile: name of the .pte file (default: stories110M.pte)
* - tokenizerFile: name of the tokenizer file (default: tokenizer.model)
*/
@RunWith(AndroidJUnit4::class)
class SanityCheck : LlmCallback {

companion object {
private const val RESOURCE_PATH = "/data/local/tmp/llama/"
private const val DEFAULT_MODEL_FILE = "stories110M.pte"
private const val DEFAULT_TOKENIZER_FILE = "tokenizer.model"
}

private lateinit var modelFile: String
private lateinit var tokenizerFile: String
private val results = mutableListOf<String>()

@Before
fun setUp() {
// Read model filenames from instrumentation arguments
val args = InstrumentationRegistry.getArguments()
modelFile = args.getString("modelFile", DEFAULT_MODEL_FILE) ?: DEFAULT_MODEL_FILE
tokenizerFile = args.getString("tokenizerFile", DEFAULT_TOKENIZER_FILE) ?: DEFAULT_TOKENIZER_FILE
Log.i("SanityCheck", "Using model: $modelFile, tokenizer: $tokenizerFile")
}

@Test
fun testLoadAndGenerate() {
val tokenizerPath = RESOURCE_PATH + tokenizerFile
val modelPath = RESOURCE_PATH + modelFile
val module = LlmModule(modelPath, tokenizerPath, 0.8f)

val loadResult = module.load()
// Check that the model can be loaded successfully
assertEquals(0, loadResult)

// Run a testing prompt
module.generate("How do you do! I'm testing llm on mobile device", this)

// Verify we got some response
assertFalse("Should receive at least one result token", results.isEmpty())
}

override fun onResult(result: String) {
results.add(result)
}

override fun onStats(result: String) {
// Not measuring performance for now
}
}
Loading