Skip to content

Commit 6bbf1bd

Browse files
authored
[js/web] upgrade version of flatbuffers (#23545)
### Description Upgrade version of flatbuffers to latest. This change fixes #23361.
1 parent 271c509 commit 6bbf1bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3507
-4118
lines changed

js/web/lib/onnxjs/attribute.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33

44
import Long from 'long';
55

6-
import { onnxruntime } from './ort-schema/flatbuffers/ort-generated';
6+
import * as ortFbs from './ort-schema/flatbuffers/ort-generated';
77
import { onnx } from './ort-schema/protobuf/onnx';
88
import { Tensor } from './tensor';
99
import { decodeUtf8String, LongUtil } from './util';
1010

11-
import ortFbs = onnxruntime.experimental.fbs;
12-
1311
export declare namespace Attribute {
1412
export interface DataTypeMap {
1513
float: number;
@@ -136,12 +134,12 @@ export class Attribute {
136134

137135
// cast LONG to number
138136
if (attrType === onnx.AttributeProto.AttributeType.INT && LongUtil.isLong(value)) {
139-
return LongUtil.longToNumber(value as Long | flatbuffers.Long);
137+
return LongUtil.longToNumber(value as bigint | Long);
140138
}
141139

142140
// cast LONG[] to number[]
143141
if (attrType === onnx.AttributeProto.AttributeType.INTS) {
144-
const arr = value as Array<number | Long | flatbuffers.Long>;
142+
const arr = value as Array<number | Long | bigint>;
145143
const numberValue: number[] = new Array<number>(arr.length);
146144

147145
for (let i = 0; i < arr.length; i++) {

js/web/lib/onnxjs/graph.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
// Licensed under the MIT License.
33

44
import { Attribute } from './attribute';
5-
import { onnxruntime } from './ort-schema/flatbuffers/ort-generated';
5+
import * as ortFbs from './ort-schema/flatbuffers/ort-generated';
66
import { onnx } from './ort-schema/protobuf/onnx';
77
import { Tensor } from './tensor';
88
import { LongUtil, MAX_CLIP, MIN_CLIP, ProtoUtil } from './util';
99

10-
import ortFbs = onnxruntime.experimental.fbs;
11-
1210
export declare namespace Graph {
1311
export interface Shape {
1412
readonly dims: readonly number[];

js/web/lib/onnxjs/model.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { flatbuffers } from 'flatbuffers';
4+
import * as flatbuffers from 'flatbuffers';
55

66
import { Graph } from './graph';
77
import { OpSet } from './opset';
8-
import { onnxruntime } from './ort-schema/flatbuffers/ort-generated';
8+
import * as ortFbs from './ort-schema/flatbuffers/ort-generated';
99
import { onnx } from './ort-schema/protobuf/onnx';
1010
import { LongUtil } from './util';
1111

12-
import ortFbs = onnxruntime.experimental.fbs;
13-
1412
export class Model {
1513
// empty model
1614
constructor() {}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# ORT Format File
22

3-
This directory contains [the generated ts file](ort-generated.ts) necessary to support the ORT file format. The file is generated from [the ORT file format schema](https://github.com/microsoft/onnxruntime/blob/d42399e1b07ce61e95aae88bc6b6ea5dcaae2011/onnxruntime/core/flatbuffers/schema/ort.fbs). Please do not directly modify [the generated ts header file](ort-generated.ts).
3+
This directory contains [the generated ts file](ort-generated.ts) necessary to support the ORT file format. The file is generated from [the ORT file format schema](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/flatbuffers/schema/ort.fbs). Please do not directly modify [the generated ts header file](ort-generated.ts).
44

5-
[The ORT file format schema](https://github.com/microsoft/onnxruntime/blob/d42399e1b07ce61e95aae88bc6b6ea5dcaae2011/onnxruntime/core/flatbuffers/schema/ort.fbs) uses [FlatBuffers](https://github.com/google/flatbuffers) serialization library. To update [its generated ts file](ort-generated.ts),
5+
[The ORT file format schema](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/flatbuffers/schema/ort.fbs) uses [FlatBuffers](https://github.com/google/flatbuffers) serialization library. To update [its generated ts file](ort-generated.ts),
66

7-
1. Download or locate the [ort.fbs](https://github.com/microsoft/onnxruntime/blob/d42399e1b07ce61e95aae88bc6b6ea5dcaae2011/onnxruntime/core/flatbuffers/schema/ort.fbs) file.
8-
2. Download FlatBuffers compiler: Download the latest flatc tool (flatc_windows.zip) from [Flatbuffers Release Page](https://github.com/google/flatbuffers/releases). Unzip and run
7+
1. Download or locate the [ort.fbs](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/flatbuffers/schema/ort.fbs) file.
8+
2. Download FlatBuffers compiler: Download the latest flatc tool (Windows.flatc.binary.zip) from [Flatbuffers Release Page](https://github.com/google/flatbuffers/releases). Unzip and run
99

10-
`> flatc_windows.exe --ts <path to ort.fbs>`
10+
`> flatc.exe --ts ort.fbs`
1111

12-
This should result in ort-generated.ts being updated.
12+
copy the generated folder `onnxruntime` to `js/web/lib/onnxjs/ort-schema/flatbuffers/` directory.
13+
14+
Update ort-generated.ts to re-export from the generated file fbs.ts under the onnxruntime directory.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// automatically generated by the FlatBuffers compiler, do not modify
2+
3+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
4+
5+
export { ArgType } from './fbs/arg-type.js';
6+
export { ArgTypeAndIndex } from './fbs/arg-type-and-index.js';
7+
export { Attribute } from './fbs/attribute.js';
8+
export { AttributeType } from './fbs/attribute-type.js';
9+
export { DeprecatedKernelCreateInfos } from './fbs/deprecated-kernel-create-infos.js';
10+
export { DeprecatedNodeIndexAndKernelDefHash } from './fbs/deprecated-node-index-and-kernel-def-hash.js';
11+
export { DeprecatedSessionState } from './fbs/deprecated-session-state.js';
12+
export { DeprecatedSubGraphSessionState } from './fbs/deprecated-sub-graph-session-state.js';
13+
export { Dimension } from './fbs/dimension.js';
14+
export { DimensionValue } from './fbs/dimension-value.js';
15+
export { DimensionValueType } from './fbs/dimension-value-type.js';
16+
export { EdgeEnd } from './fbs/edge-end.js';
17+
export { Graph } from './fbs/graph.js';
18+
export { InferenceSession } from './fbs/inference-session.js';
19+
export { KernelTypeStrArgsEntry } from './fbs/kernel-type-str-args-entry.js';
20+
export { KernelTypeStrResolver } from './fbs/kernel-type-str-resolver.js';
21+
export { MapType } from './fbs/map-type.js';
22+
export { Model } from './fbs/model.js';
23+
export { Node } from './fbs/node.js';
24+
export { NodeEdge } from './fbs/node-edge.js';
25+
export { NodeType } from './fbs/node-type.js';
26+
export { NodesToOptimizeIndices } from './fbs/nodes-to-optimize-indices.js';
27+
export { OpIdKernelTypeStrArgsEntry } from './fbs/op-id-kernel-type-str-args-entry.js';
28+
export { OperatorSetId } from './fbs/operator-set-id.js';
29+
export { RuntimeOptimizationRecord } from './fbs/runtime-optimization-record.js';
30+
export { RuntimeOptimizationRecordContainerEntry } from './fbs/runtime-optimization-record-container-entry.js';
31+
export { RuntimeOptimizations } from './fbs/runtime-optimizations.js';
32+
export { SequenceType } from './fbs/sequence-type.js';
33+
export { Shape } from './fbs/shape.js';
34+
export { SparseTensor } from './fbs/sparse-tensor.js';
35+
export { StringStringEntry } from './fbs/string-string-entry.js';
36+
export { Tensor } from './fbs/tensor.js';
37+
export { TensorDataType } from './fbs/tensor-data-type.js';
38+
export { TensorTypeAndShape } from './fbs/tensor-type-and-shape.js';
39+
export { TypeInfo } from './fbs/type-info.js';
40+
export { TypeInfoValue } from './fbs/type-info-value.js';
41+
export { ValueInfo } from './fbs/value-info.js';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// automatically generated by the FlatBuffers compiler, do not modify
2+
3+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
4+
5+
import * as flatbuffers from 'flatbuffers';
6+
7+
import { ArgType } from '../../onnxruntime/fbs/arg-type.js';
8+
9+
export class ArgTypeAndIndex {
10+
bb: flatbuffers.ByteBuffer | null = null;
11+
bb_pos = 0;
12+
__init(i: number, bb: flatbuffers.ByteBuffer): ArgTypeAndIndex {
13+
this.bb_pos = i;
14+
this.bb = bb;
15+
return this;
16+
}
17+
18+
static getRootAsArgTypeAndIndex(bb: flatbuffers.ByteBuffer, obj?: ArgTypeAndIndex): ArgTypeAndIndex {
19+
return (obj || new ArgTypeAndIndex()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
20+
}
21+
22+
static getSizePrefixedRootAsArgTypeAndIndex(bb: flatbuffers.ByteBuffer, obj?: ArgTypeAndIndex): ArgTypeAndIndex {
23+
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
24+
return (obj || new ArgTypeAndIndex()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
25+
}
26+
27+
argType(): ArgType {
28+
const offset = this.bb!.__offset(this.bb_pos, 4);
29+
return offset ? this.bb!.readInt8(this.bb_pos + offset) : ArgType.INPUT;
30+
}
31+
32+
index(): number {
33+
const offset = this.bb!.__offset(this.bb_pos, 6);
34+
return offset ? this.bb!.readUint32(this.bb_pos + offset) : 0;
35+
}
36+
37+
static startArgTypeAndIndex(builder: flatbuffers.Builder) {
38+
builder.startObject(2);
39+
}
40+
41+
static addArgType(builder: flatbuffers.Builder, argType: ArgType) {
42+
builder.addFieldInt8(0, argType, ArgType.INPUT);
43+
}
44+
45+
static addIndex(builder: flatbuffers.Builder, index: number) {
46+
builder.addFieldInt32(1, index, 0);
47+
}
48+
49+
static endArgTypeAndIndex(builder: flatbuffers.Builder): flatbuffers.Offset {
50+
const offset = builder.endObject();
51+
return offset;
52+
}
53+
54+
static createArgTypeAndIndex(builder: flatbuffers.Builder, argType: ArgType, index: number): flatbuffers.Offset {
55+
ArgTypeAndIndex.startArgTypeAndIndex(builder);
56+
ArgTypeAndIndex.addArgType(builder, argType);
57+
ArgTypeAndIndex.addIndex(builder, index);
58+
return ArgTypeAndIndex.endArgTypeAndIndex(builder);
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// automatically generated by the FlatBuffers compiler, do not modify
2+
3+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
4+
5+
export enum ArgType {
6+
INPUT = 0,
7+
OUTPUT = 1,
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// automatically generated by the FlatBuffers compiler, do not modify
2+
3+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
4+
5+
export enum AttributeType {
6+
UNDEFINED = 0,
7+
FLOAT = 1,
8+
INT = 2,
9+
STRING = 3,
10+
TENSOR = 4,
11+
GRAPH = 5,
12+
FLOATS = 6,
13+
INTS = 7,
14+
STRINGS = 8,
15+
TENSORS = 9,
16+
GRAPHS = 10,
17+
SPARSE_TENSOR = 11,
18+
SPARSE_TENSORS = 12,
19+
}

0 commit comments

Comments
 (0)