Skip to content

Commit

Permalink
Fix indexeddb for 1GB models
Browse files Browse the repository at this point in the history
Fixes tensorflow#7702 by concatenating model weights into a single ArrayBuffer before
sending them to IndexedDB. A better solution would be to store the model as
multiple records, but this quick fix is easy to implement solves the issue for
most current models (~1GB).
  • Loading branch information
mattsoulanille committed May 30, 2023
1 parent 92465b7 commit 071ccdb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tfjs-core/src/io/indexed_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {env} from '../environment';
import {getModelArtifactsInfoForJSON} from './io_utils';
import {IORouter, IORouterRegistry} from './router_registry';
import {IOHandler, ModelArtifacts, ModelArtifactsInfo, ModelStoreManager, SaveResult} from './types';
import {CompositeArrayBuffer} from './composite_array_buffer';

const DATABASE_NAME = 'tensorflowjs';
const DATABASE_VERSION = 1;
Expand Down Expand Up @@ -157,6 +158,13 @@ export class BrowserIndexedDB implements IOHandler {
modelTx.oncomplete = () => db.close();
} else {
// Put model into object store.

// Concatenate all the model weights into a single ArrayBuffer. Large
// models (~1GB) have problems saving if they are not concatenated.
// TODO(mattSoulanille): Save large models to multiple indexeddb
// records.
modelArtifacts.weightData = new CompositeArrayBuffer(
modelArtifacts.weightData).slice();
const modelArtifactsInfo: ModelArtifactsInfo =
getModelArtifactsInfoForJSON(modelArtifacts);
// First, put ModelArtifactsInfo into info store.
Expand Down

0 comments on commit 071ccdb

Please sign in to comment.