Skip to content

Commit

Permalink
Allocate one big weights chunk when parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
DrA1ex committed Sep 26, 2023
1 parent f32f599 commit 8be1d84
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/app/neural-network/serialization/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ export class BinarySerializer {
const model = new modelT(optimizer, loss);

const dataOffset = BigInt64Array.BYTES_PER_ELEMENT + metaSize;
const tensorsDataArray = new ChunkedArrayBuffer([data], dataOffset);
const tensorsDataArray = data.slice(dataOffset);

let layerIndex = 0;
for (const layerConf of headerMeta.layers) {
const biasesMeta = headerTensors[layerConf.biasesKey];
const biasesDataType = this._getArrayT(biasesMeta.dtype);

const biasesExpectedSize = biasesMeta.shape[0];
const biases = tensorsDataArray.createTypedArray(
biasesDataType,
const biases = new biasesDataType(
tensorsDataArray,
biasesMeta.offsets[0],
biasesExpectedSize
);
Expand All @@ -167,8 +167,8 @@ export class BinarySerializer {
const weightsDataType = this._getArrayT(weightsMeta.dtype);

const weightExpectedSize = weightsMeta.shape[0] * weightsMeta.shape[1];
const weightsData = tensorsDataArray.createTypedArray(
weightsDataType,
const weightsData = new weightsDataType(
tensorsDataArray,
weightsMeta.offsets[0],
weightExpectedSize
);
Expand Down

0 comments on commit 8be1d84

Please sign in to comment.