Skip to content

Commit 90dc82b

Browse files
authored
[Inference] LoRA: use the precomputed adapterWeightsPath property (#1379)
Following @Wauplin 's comment [here](huggingface/huggingface_hub#3005 (comment)) Pre-requisite: merge and deploy [this internal PR first](huggingface-internal/moon-landing#13498)
1 parent a2a85fc commit 90dc82b

File tree

2 files changed

+1
-27
lines changed

2 files changed

+1
-27
lines changed

packages/inference/src/lib/getInferenceProviderMapping.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { typedInclude } from "../utils/typedInclude";
88
export const inferenceProviderMappingCache = new Map<ModelId, InferenceProviderMapping>();
99

1010
export type InferenceProviderMapping = Partial<
11-
Record<InferenceProvider, Omit<InferenceProviderModelMapping, "hfModelId" | "adapterWeightsPath">>
11+
Record<InferenceProvider, Omit<InferenceProviderModelMapping, "hfModelId">>
1212
>;
1313

1414
export interface InferenceProviderModelMapping {
@@ -74,22 +74,6 @@ export async function getInferenceProviderMapping(
7474
`Model ${params.modelId} is in staging mode for provider ${params.provider}. Meant for test purposes only.`
7575
);
7676
}
77-
if (providerMapping.adapter === "lora") {
78-
const treeResp = await (options?.fetch ?? fetch)(`${HF_HUB_URL}/api/models/${params.modelId}/tree/main`);
79-
if (!treeResp.ok) {
80-
throw new Error(`Unable to fetch the model tree for ${params.modelId}.`);
81-
}
82-
const tree: Array<{ type: "file" | "directory"; path: string }> = await treeResp.json();
83-
const adapterWeightsPath = tree.find(({ type, path }) => type === "file" && path.endsWith(".safetensors"))?.path;
84-
if (!adapterWeightsPath) {
85-
throw new Error(`No .safetensors file found in the model tree for ${params.modelId}.`);
86-
}
87-
return {
88-
...providerMapping,
89-
hfModelId: params.modelId,
90-
adapterWeightsPath,
91-
};
92-
}
9377
return { ...providerMapping, hfModelId: params.modelId };
9478
}
9579
return null;

packages/inference/src/providers/fal-ai.ts

-10
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,6 @@ export class FalAITextToImageTask extends FalAITask implements TextToImageTaskHe
8686
...(params.args.parameters as Record<string, unknown>),
8787
sync_mode: true,
8888
prompt: params.args.inputs,
89-
...(params.mapping?.adapter === "lora" && params.mapping.adapterWeightsPath
90-
? {
91-
loras: [
92-
{
93-
path: buildLoraPath(params.mapping.hfModelId, params.mapping.adapterWeightsPath),
94-
scale: 1,
95-
},
96-
],
97-
}
98-
: undefined),
9989
};
10090

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

0 commit comments

Comments
 (0)