Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ See the Speedometer repo for a more detailed explanation, e.g., in which phases
- Workloads are in `resources/transformers-js/` and `resources/litert-js`.
- Shared files are in `resources/shared/`, which is depended-upon as a local package.
- The default suite / tests to run are in `resources/default-tests.mjs`.
- Cleaning build artifacts and cached models (optional): Run `npm run clean` in the root directory. This will delete the `dist` directories and clear cached models for all workloads (while preserving the large `gemma` model to avoid unnecessary re-downloads).

## How to Run Individual Workload

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"license": "SEE LICENSE IN LICENSE",
"scripts": {
"build": "node script/build.mjs",
"clean": "node script/clean.mjs",
Comment thread
rmahdav marked this conversation as resolved.
"dev": "node tests/server.mjs",
"lint:check": "eslint **/*.{js,mjs,jsx,ts,tsx}",
"lint:fix": "eslint \"**/*.{js,mjs,jsx,ts,tsx}\" --fix",
Expand Down
5 changes: 5 additions & 0 deletions resources/experimental/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 28 additions & 23 deletions resources/experimental/src/download-models.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,11 @@ async function downloadModels() {
env.allowRemoteModels = true;

try {
// Download models that work with pipeline
for (const modelInfo of MODELS_TO_DOWNLOAD) {
const { id: modelId, task: modelTask, dtype: modelDType } = modelInfo;

const cacheKey = `${modelId}-${modelTask}-${modelDType}`;
if (cache.has(cacheKey)) {
console.log(`Model ${modelId} (${modelTask}, dtype: ${modelDType}) already cached. Skipping.`);
continue;
}

console.log(`Downloading files for ${modelId} (${modelTask}, dtype: ${modelDType})...`);

await retry(() => pipeline(
modelTask,
modelId,
{
cache_dir: env.localModelPath,
dtype: modelDType
}));

console.log(`Successfully downloaded and cached ${modelId}`);
cache.put(cacheKey);
}
console.log(`Downloading all experimental models in parallel...`);
await Promise.all(
MODELS_TO_DOWNLOAD.map(modelInfo => downloadPipelineModel(modelInfo, cache))
);
console.log(`Successfully checked and downloaded all models.`);

} catch (err) {
console.error("Model download failed:", err);
Expand All @@ -64,6 +46,29 @@ async function downloadModels() {
env.allowRemoteModels = originalAllowRemote;
}

async function downloadPipelineModel(modelInfo, cache) {
const { id: modelId, task: modelTask, dtype: modelDType } = modelInfo;

const cacheKey = `${modelId}-${modelTask}-${modelDType}`;
if (cache.has(cacheKey)) {
console.log(`Model ${modelId} (${modelTask}, dtype: ${modelDType}) already cached. Skipping.`);
return;
}

console.log(`Downloading files for ${modelId} (${modelTask}, dtype: ${modelDType})...`);

await retry(() => pipeline(
modelTask,
modelId,
{
cache_dir: env.localModelPath,
dtype: modelDType
}));

console.log(`Successfully downloaded and cached ${modelId}`);
cache.put(cacheKey);
}

downloadModels().catch(err => {
console.error("Download process terminated.");
process.exit(1);
Expand Down
10 changes: 9 additions & 1 deletion resources/litert-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 53 additions & 44 deletions resources/litert-js/src/download-models.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ const CACHE_VERSION = 1;

const MODELS_TO_DOWNLOAD = [
{
repo: 'qualcomm/MediaPipe-Selfie-Segmentation',
repo: 'qualcomm/MediaPipe-Selfie-Segmentation',
filename: 'mediapipe_selfie-tflite-float.zip',
url: 'https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/mediapipe_selfie/releases/v0.46.0/mediapipe_selfie-tflite-float.zip'
},
{
repo: 'qualcomm/MobileNet-v3-Small',
{
repo: 'qualcomm/MobileNet-v3-Small',
filename: 'mobilenet_v3_small-tflite-float.zip',
url: 'https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/mobilenet_v3_small/releases/v0.46.0/mobilenet_v3_small-tflite-float.zip'
},
{
repo: 'qualcomm/MediaPipe-Hand-Detection',
{
repo: 'qualcomm/MediaPipe-Hand-Detection',
filename: 'mediapipe_hand-tflite-float.zip',
url: 'https://qaihub-public-assets.s3.us-west-2.amazonaws.com/qai-hub-models/models/mediapipe_hand/releases/v0.46.0/mediapipe_hand-tflite-float.zip'
}
Expand All @@ -34,59 +34,68 @@ async function downloadModels() {

if (!fs.existsSync(MODEL_DIR)) {
console.log(`Creating directory: **${MODEL_DIR}**`);
fs.mkdirSync(MODEL_DIR, { recursive: true });
fs.mkdirSync(MODEL_DIR, { recursive: true });
}

console.log(`Starting TFLite model downloads to: **${MODEL_DIR}**`);

for (const modelInfo of MODELS_TO_DOWNLOAD) {
const { repo, filename, url } = modelInfo;
try {
await Promise.all(
MODELS_TO_DOWNLOAD.map(modelInfo => downloadModel(modelInfo, cache))
);
} catch (err) {
console.error("TFLite model download failed:", err);
throw err;
}
console.log('TFLite download process finished.');
}

const cacheKey = `${repo}-${filename}`;
if (cache.has(cacheKey)) {
console.log(`Model ${filename} from ${repo} already cached. Skipping.`);
continue;
}
async function downloadModel(modelInfo, cache) {
const { repo, filename, url } = modelInfo;

const modelUrl = url;
const outputPath = path.join(MODEL_DIR, path.basename(filename));
const cacheKey = `${repo}-${filename}`;
if (cache.has(cacheKey)) {
console.log(`Model ${filename} from ${repo} already cached. Skipping.`);
return;
}

console.log(`\nAttempting to download **${filename}** from **${repo}**...`);
console.log(`URL: ${modelUrl}`);
const modelUrl = url;
const outputPath = path.join(MODEL_DIR, path.basename(filename));

try {
await retry(async () => {
const response = await fetch(modelUrl);
console.log(`\nAttempting to download **${filename}** from **${repo}**...`);
console.log(`URL: ${modelUrl}`);

if (!response.ok) {
throw new Error(`Failed to fetch: ${response.statusText} (${response.status})`);
}
try {
await retry(async () => {
const response = await fetch(modelUrl);

const fileStream = fs.createWriteStream(outputPath);
await new Promise((resolve, reject) => {
response.body.pipe(fileStream);
response.body.on('error', reject);
fileStream.on('finish', resolve);
});
});

console.log(`Successfully downloaded **${filename}** to **${outputPath}**`);

if (path.extname(filename) === '.zip') {
console.log(`Extracting **${filename}**...`);
const zip = new AdmZip(outputPath);
zip.extractAllTo(MODEL_DIR, true);
console.log(`Successfully extracted **${filename}** to **${MODEL_DIR}**`);
fs.unlinkSync(outputPath);
console.log(`Deleted zip file **${outputPath}**`);
if (!response.ok) {
throw new Error(`Failed to fetch: ${response.statusText} (${response.status})`);
}

cache.put(cacheKey);
} catch (err) {
console.error(`Model download failed for ${repo}/${filename} after retries:`, err.message);
const fileStream = fs.createWriteStream(outputPath);
await new Promise((resolve, reject) => {
response.body.pipe(fileStream);
response.body.on('error', reject);
fileStream.on('finish', resolve);
});
});

console.log(`Successfully downloaded **${filename}** to **${outputPath}**`);

if (path.extname(filename) === '.zip') {
console.log(`Extracting **${filename}**...`);
const zip = new AdmZip(outputPath);
zip.extractAllTo(MODEL_DIR, true);
console.log(`Successfully extracted **${filename}** to **${MODEL_DIR}**`);
fs.unlinkSync(outputPath);
console.log(`Deleted zip file **${outputPath}**`);
}

cache.put(cacheKey);
} catch (err) {
console.error(`Model download failed for ${repo}/${filename} after retries:`, err.message);
}
console.log('TFLite download process finished.');
}

downloadModels().catch(err => {
Expand Down
5 changes: 5 additions & 0 deletions resources/transformers-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading