Skip to content

[Inference] LoRA: use the precomputed adapterWeightsPath property #1379

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

Merged
merged 3 commits into from
Apr 25, 2025
Merged
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
18 changes: 1 addition & 17 deletions packages/inference/src/lib/getInferenceProviderMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { typedInclude } from "../utils/typedInclude";
export const inferenceProviderMappingCache = new Map<ModelId, InferenceProviderMapping>();

export type InferenceProviderMapping = Partial<
Record<InferenceProvider, Omit<InferenceProviderModelMapping, "hfModelId" | "adapterWeightsPath">>
Record<InferenceProvider, Omit<InferenceProviderModelMapping, "hfModelId">>
>;

export interface InferenceProviderModelMapping {
Expand Down Expand Up @@ -74,22 +74,6 @@ export async function getInferenceProviderMapping(
`Model ${params.modelId} is in staging mode for provider ${params.provider}. Meant for test purposes only.`
);
}
if (providerMapping.adapter === "lora") {
const treeResp = await (options?.fetch ?? fetch)(`${HF_HUB_URL}/api/models/${params.modelId}/tree/main`);
if (!treeResp.ok) {
throw new Error(`Unable to fetch the model tree for ${params.modelId}.`);
}
const tree: Array<{ type: "file" | "directory"; path: string }> = await treeResp.json();
const adapterWeightsPath = tree.find(({ type, path }) => type === "file" && path.endsWith(".safetensors"))?.path;
if (!adapterWeightsPath) {
throw new Error(`No .safetensors file found in the model tree for ${params.modelId}.`);
}
return {
...providerMapping,
hfModelId: params.modelId,
adapterWeightsPath,
};
}
return { ...providerMapping, hfModelId: params.modelId };
}
return null;
Expand Down
10 changes: 0 additions & 10 deletions packages/inference/src/providers/fal-ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,6 @@ export class FalAITextToImageTask extends FalAITask implements TextToImageTaskHe
...(params.args.parameters as Record<string, unknown>),
sync_mode: true,
prompt: params.args.inputs,
...(params.mapping?.adapter === "lora" && params.mapping.adapterWeightsPath
? {
loras: [
{
path: buildLoraPath(params.mapping.hfModelId, params.mapping.adapterWeightsPath),
scale: 1,
},
],
}
: undefined),
};

if (params.mapping?.adapter === "lora" && params.mapping.adapterWeightsPath) {
Expand Down