Skip to content
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

Cache path vs Local path #602

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions src/utils/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,9 @@ export async function getModelFile(path_or_repo_id, filename, fatal = true, opti
const revision = options.revision ?? 'main';

let requestURL = pathJoin(path_or_repo_id, filename);
let localPath = pathJoin(env.localModelPath, requestURL);
let cachePath = pathJoin(env.localModelPath, requestURL);

let localPath = requestURL;
let remoteURL = pathJoin(
env.remoteHost,
env.remotePathTemplate
Expand Down Expand Up @@ -422,7 +423,7 @@ export async function getModelFile(path_or_repo_id, filename, fatal = true, opti
// 1. We first try to get from cache using the local path. In some environments (like deno),
// non-URL cache keys are not allowed. In these cases, `response` will be undefined.
// 2. If no response is found, we try to get from cache using the remote URL or file system cache.
response = await tryCache(cache, localPath, proposedCacheKey);
response = await tryCache(cache, cachePath, proposedCacheKey);
}

const cacheHit = response !== undefined;
Expand All @@ -444,9 +445,9 @@ export async function getModelFile(path_or_repo_id, filename, fatal = true, opti
console.warn(`Unable to load from local path "${localPath}": "${e}"`);
}
} else if (options.local_files_only) {
throw new Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${requestURL}.`);
throw new Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${localPath}.`);
} else if (!env.allowRemoteModels) {
throw new Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${requestURL}.`);
throw new Error(`\`env.allowRemoteModels=false\`, but attempted to load a remote file from: ${localPath}.`);
}
}

Expand Down