ccheney commited on
Commit
fec4d98
·
verified ·
1 Parent(s): 9253046

Upload folder using huggingface_hub

Browse files
packages/benchmark/hf-space/Dockerfile CHANGED
@@ -111,8 +111,7 @@ ENV NODE_ENV=production
111
  ENV BENCHMARK_VERBOSE=true
112
  ENV NODE_OPTIONS="--max-old-space-size=24576"
113
 
114
- # GPU mode (onnxruntime-node auto-detects CUDA)
115
- # Using fp32 for compatibility - fp16 models can have issues
116
  ENV EMBEDDER_DEVICE=cuda
117
  ENV EMBEDDER_DTYPE=fp32
118
  ENV QDRANT_URL=http://localhost:6333
 
111
  ENV BENCHMARK_VERBOSE=true
112
  ENV NODE_OPTIONS="--max-old-space-size=24576"
113
 
114
+ # GPU mode
 
115
  ENV EMBEDDER_DEVICE=cuda
116
  ENV EMBEDDER_DTYPE=fp32
117
  ENV QDRANT_URL=http://localhost:6333
packages/benchmark/hf-space/run.sh CHANGED
@@ -109,10 +109,13 @@ fi
109
  # -----------------------------------------------------------------------------
110
  # Clear model cache to avoid corrupted files
111
  # -----------------------------------------------------------------------------
112
- echo "Clearing transformers model cache..."
113
- rm -rf /app/.cache/huggingface/transformers/*
 
 
114
  rm -rf /app/node_modules/@huggingface/transformers/.cache/*
115
  mkdir -p /app/.cache
 
116
 
117
  # -----------------------------------------------------------------------------
118
  # Create Server with Ingest + Benchmark APIs
 
109
  # -----------------------------------------------------------------------------
110
  # Clear model cache to avoid corrupted files
111
  # -----------------------------------------------------------------------------
112
+ echo "Clearing ALL model caches to avoid corrupted files..."
113
+ rm -rf /app/.cache/*
114
+ rm -rf /root/.cache/huggingface
115
+ rm -rf /home/user/.cache/huggingface 2>/dev/null || true
116
  rm -rf /app/node_modules/@huggingface/transformers/.cache/*
117
  mkdir -p /app/.cache
118
+ echo "Cache cleared"
119
 
120
  # -----------------------------------------------------------------------------
121
  # Create Server with Ingest + Benchmark APIs
packages/search/src/services/embedder-factory.ts CHANGED
@@ -130,6 +130,7 @@ type ExtractorFn = (
130
  */
131
  export class ConfigurableTextEmbedder extends BasePipelineEmbedder<EmbedderConfig> {
132
  private static instances = new Map<string, unknown>();
 
133
  private sparseEmbedder?: SpladeEmbedder;
134
  private modelConfig: ModelConfig;
135
  private includeSparse: boolean;
@@ -172,24 +173,42 @@ export class ConfigurableTextEmbedder extends BasePipelineEmbedder<EmbedderConfi
172
 
173
  /**
174
  * Get or create singleton pipeline instance for this model.
 
175
  */
176
  protected async getInstance(): Promise<ExtractorFn> {
177
  const key = this.modelConfig.hfModel;
178
- if (!ConfigurableTextEmbedder.instances.has(key)) {
179
- const device = this.config.device ?? getDefaultDevice();
180
- const dtype = this.config.dtype ?? getDefaultDtype();
181
- console.log(`[ConfigurableEmbedder] Loading ${key} on device=${device} dtype=${dtype}`);
182
- const start = Date.now();
183
- ConfigurableTextEmbedder.instances.set(
184
- key,
185
- await pipeline("feature-extraction", this.modelConfig.hfModel, {
186
- dtype,
187
- device,
188
- }),
189
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  console.log(`[ConfigurableEmbedder] Loaded in ${Date.now() - start}ms`);
 
 
 
191
  }
192
- return ConfigurableTextEmbedder.instances.get(key) as ExtractorFn;
193
  }
194
 
195
  /**
 
130
  */
131
  export class ConfigurableTextEmbedder extends BasePipelineEmbedder<EmbedderConfig> {
132
  private static instances = new Map<string, unknown>();
133
+ private static loadingPromises = new Map<string, Promise<unknown>>();
134
  private sparseEmbedder?: SpladeEmbedder;
135
  private modelConfig: ModelConfig;
136
  private includeSparse: boolean;
 
173
 
174
  /**
175
  * Get or create singleton pipeline instance for this model.
176
+ * Uses a loading promise to prevent concurrent model loading race conditions.
177
  */
178
  protected async getInstance(): Promise<ExtractorFn> {
179
  const key = this.modelConfig.hfModel;
180
+
181
+ // Already loaded - return immediately
182
+ if (ConfigurableTextEmbedder.instances.has(key)) {
183
+ return ConfigurableTextEmbedder.instances.get(key) as ExtractorFn;
184
+ }
185
+
186
+ // Another call is already loading - wait for it
187
+ if (ConfigurableTextEmbedder.loadingPromises.has(key)) {
188
+ await ConfigurableTextEmbedder.loadingPromises.get(key);
189
+ return ConfigurableTextEmbedder.instances.get(key) as ExtractorFn;
190
+ }
191
+
192
+ // We're the first - create and store the loading promise
193
+ const device = this.config.device ?? getDefaultDevice();
194
+ const dtype = this.config.dtype ?? getDefaultDtype();
195
+ console.log(`[ConfigurableEmbedder] Loading ${key} on device=${device} dtype=${dtype}`);
196
+ const start = Date.now();
197
+
198
+ const loadPromise = pipeline("feature-extraction", this.modelConfig.hfModel, {
199
+ dtype,
200
+ device,
201
+ });
202
+ ConfigurableTextEmbedder.loadingPromises.set(key, loadPromise);
203
+
204
+ try {
205
+ const instance = await loadPromise;
206
+ ConfigurableTextEmbedder.instances.set(key, instance);
207
  console.log(`[ConfigurableEmbedder] Loaded in ${Date.now() - start}ms`);
208
+ return instance as ExtractorFn;
209
+ } finally {
210
+ ConfigurableTextEmbedder.loadingPromises.delete(key);
211
  }
 
212
  }
213
 
214
  /**
packages/search/src/services/text-embedder.ts CHANGED
@@ -41,6 +41,7 @@ type ExtractorFn = (
41
  */
42
  export class TextEmbedder extends BasePipelineEmbedder<TextEmbedderConfig> {
43
  private static instance: unknown = null;
 
44
  private sparseEmbedder = new SpladeEmbedder();
45
 
46
  constructor(config: Partial<TextEmbedderConfig> = {}) {
@@ -49,21 +50,40 @@ export class TextEmbedder extends BasePipelineEmbedder<TextEmbedderConfig> {
49
 
50
  /**
51
  * Get or create singleton pipeline instance.
 
52
  */
53
  protected async getInstance(): Promise<ExtractorFn> {
54
- if (!TextEmbedder.instance) {
55
- const device = this.config.device ?? getDefaultDevice();
56
- const dtype = this.config.dtype ?? getDefaultDtype();
57
- console.log(
58
- `[TextEmbedder] Loading model ${this.config.model} on device=${device} dtype=${dtype}`,
59
- );
60
- TextEmbedder.instance = await pipeline("feature-extraction", this.config.model, {
61
- dtype,
62
- device,
63
- });
64
- console.log(`[TextEmbedder] Model loaded successfully`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  }
66
- return TextEmbedder.instance as ExtractorFn;
67
  }
68
 
69
  /**
 
41
  */
42
  export class TextEmbedder extends BasePipelineEmbedder<TextEmbedderConfig> {
43
  private static instance: unknown = null;
44
+ private static loadingPromise: Promise<unknown> | null = null;
45
  private sparseEmbedder = new SpladeEmbedder();
46
 
47
  constructor(config: Partial<TextEmbedderConfig> = {}) {
 
50
 
51
  /**
52
  * Get or create singleton pipeline instance.
53
+ * Uses a loading promise to prevent concurrent model loading race conditions.
54
  */
55
  protected async getInstance(): Promise<ExtractorFn> {
56
+ // Already loaded - return immediately
57
+ if (TextEmbedder.instance) {
58
+ return TextEmbedder.instance as ExtractorFn;
59
+ }
60
+
61
+ // Another call is already loading - wait for it
62
+ if (TextEmbedder.loadingPromise) {
63
+ await TextEmbedder.loadingPromise;
64
+ return TextEmbedder.instance as ExtractorFn;
65
+ }
66
+
67
+ // We're the first - create and store the loading promise
68
+ const device = this.config.device ?? getDefaultDevice();
69
+ const dtype = this.config.dtype ?? getDefaultDtype();
70
+ console.log(
71
+ `[TextEmbedder] Loading model ${this.config.model} on device=${device} dtype=${dtype}`,
72
+ );
73
+ const start = Date.now();
74
+
75
+ TextEmbedder.loadingPromise = pipeline("feature-extraction", this.config.model, {
76
+ dtype,
77
+ device,
78
+ }) as Promise<unknown>;
79
+
80
+ try {
81
+ TextEmbedder.instance = await TextEmbedder.loadingPromise;
82
+ console.log(`[TextEmbedder] Model loaded in ${Date.now() - start}ms`);
83
+ return TextEmbedder.instance as ExtractorFn;
84
+ } finally {
85
+ TextEmbedder.loadingPromise = null;
86
  }
 
87
  }
88
 
89
  /**
packages/storage/src/falkor.test.ts CHANGED
@@ -1,9 +1,12 @@
1
  import { afterAll, beforeAll, describe, expect, it } from "vitest";
2
  import { createFalkorClient } from "./falkor";
3
 
 
 
 
4
  const client = createFalkorClient();
5
 
6
- describe("FalkorClient", () => {
7
  beforeAll(async () => {
8
  await client.connect();
9
  });
 
1
  import { afterAll, beforeAll, describe, expect, it } from "vitest";
2
  import { createFalkorClient } from "./falkor";
3
 
4
+ // Skip integration tests when infrastructure isn't running
5
+ const SKIP_INTEGRATION = process.env.SKIP_INTEGRATION === "true" || !process.env.CI;
6
+
7
  const client = createFalkorClient();
8
 
9
+ describe.skipIf(SKIP_INTEGRATION)("FalkorClient", () => {
10
  beforeAll(async () => {
11
  await client.connect();
12
  });