fix: use fp32 models consistently everywhere to ensure compatibility
Changed default dtype from q8 to fp32 across all embedding implementations: - embedding.ts: Default dtype changed to fp32 - worker-embedding.ts: Use fp32 for consistency - universal-memory-manager.ts: Use fp32 for consistency - lightweight-embedder.ts: Use fp32 for consistency - hybridModelManager.ts: Use fp32 for all configurations This ensures we use the exact same model (model.onnx) everywhere, maintaining data compatibility and avoiding 404 errors for quantized models.
This commit is contained in:
parent
5d2123b266
commit
10b772423b
11 changed files with 11 additions and 30742 deletions
|
|
@ -113,7 +113,7 @@ export class LightweightEmbedder {
|
|||
console.log('⚠️ Loading ONNX model for complex text...')
|
||||
const { TransformerEmbedding } = await import('../utils/embedding.js')
|
||||
this.onnxEmbedder = new TransformerEmbedding({
|
||||
dtype: 'q8',
|
||||
dtype: 'fp32',
|
||||
verbose: false
|
||||
})
|
||||
await this.onnxEmbedder.init()
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ export class UniversalMemoryManager {
|
|||
|
||||
this.embeddingFunction = new TransformerEmbedding({
|
||||
verbose: false,
|
||||
dtype: 'q8',
|
||||
dtype: 'fp32',
|
||||
localFilesOnly: process.env.BRAINY_ALLOW_REMOTE_MODELS !== 'true'
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ async function initModel(): Promise<void> {
|
|||
if (!model) {
|
||||
model = new TransformerEmbedding({
|
||||
verbose: false,
|
||||
dtype: 'q8',
|
||||
dtype: 'fp32',
|
||||
localFilesOnly: process.env.BRAINY_ALLOW_REMOTE_MODELS !== 'true'
|
||||
})
|
||||
await model.init()
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ export class TransformerEmbedding implements EmbeddingModel {
|
|||
verbose: this.verbose,
|
||||
cacheDir: options.cacheDir || './models',
|
||||
localFilesOnly: localFilesOnly,
|
||||
dtype: options.dtype || 'q8', // Changed from fp32 to q8 for 75% memory reduction
|
||||
dtype: options.dtype || 'fp32', // Use fp32 by default as quantized models aren't available on CDN
|
||||
device: options.device || 'auto'
|
||||
}
|
||||
|
||||
|
|
@ -262,7 +262,7 @@ export class TransformerEmbedding implements EmbeddingModel {
|
|||
const pipelineOptions: any = {
|
||||
cache_dir: cacheDir,
|
||||
local_files_only: isBrowser() ? false : this.options.localFilesOnly,
|
||||
dtype: this.options.dtype || 'q8', // Use quantized model for lower memory
|
||||
dtype: this.options.dtype || 'fp32', // Use fp32 model as quantized models aren't available on CDN
|
||||
// CRITICAL: ONNX memory optimizations
|
||||
session_options: {
|
||||
enableCpuMemArena: false, // Disable pre-allocated memory arena
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ class HybridModelManager {
|
|||
// Smart configuration based on environment
|
||||
let options: TransformerEmbeddingOptions = {
|
||||
verbose: !isTest && !isServerless,
|
||||
dtype: 'q8',
|
||||
dtype: 'fp32',
|
||||
device: 'cpu'
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ class HybridModelManager {
|
|||
options = {
|
||||
...options,
|
||||
localFilesOnly: forceLocalOnly || false, // Respect environment variable
|
||||
dtype: 'q8',
|
||||
dtype: 'fp32',
|
||||
device: 'cpu',
|
||||
verbose: false
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ class HybridModelManager {
|
|||
options = {
|
||||
...options,
|
||||
localFilesOnly: forceLocalOnly || true, // Default true for serverless, but respect env
|
||||
dtype: 'q8',
|
||||
dtype: 'fp32',
|
||||
device: 'cpu',
|
||||
verbose: false
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ class HybridModelManager {
|
|||
options = {
|
||||
...options,
|
||||
localFilesOnly: forceLocalOnly || false, // Respect environment variable for tests
|
||||
dtype: 'q8',
|
||||
dtype: 'fp32',
|
||||
device: 'cpu',
|
||||
verbose: false
|
||||
}
|
||||
|
|
@ -146,7 +146,7 @@ class HybridModelManager {
|
|||
options = {
|
||||
...options,
|
||||
localFilesOnly: forceLocalOnly || false, // Respect environment variable for default node
|
||||
dtype: 'q8',
|
||||
dtype: 'fp32',
|
||||
device: 'auto',
|
||||
verbose: true
|
||||
}
|
||||
|
|
@ -201,7 +201,7 @@ class HybridModelManager {
|
|||
{ ...options, localFilesOnly: false, verbose: true, source: 'fallback-verbose' },
|
||||
|
||||
// 3. Last resort: basic configuration
|
||||
{ verbose: false, dtype: 'q8' as const, device: 'cpu' as const, localFilesOnly: false, source: 'last-resort' }
|
||||
{ verbose: false, dtype: 'fp32' as const, device: 'cpu' as const, localFilesOnly: false, source: 'last-resort' }
|
||||
]
|
||||
|
||||
let lastError: Error | null = null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue