Browse Source

Update protoc.js

Lutz Roeder 1 year ago
parent
commit
082c7e04fd
19 changed files with 537 additions and 61 deletions
  1. 1 1
      package.js
  2. 476 0
      source/pytorch-proto.js
  3. 1 1
      tools/bigdl
  4. 1 1
      tools/caffe
  5. 0 38
      tools/caffe2
  6. 1 1
      tools/cntk
  7. 1 1
      tools/coreml
  8. 1 1
      tools/dnn
  9. 1 1
      tools/mediapipe
  10. 1 1
      tools/nnabla
  11. 1 1
      tools/om
  12. 1 1
      tools/onnx
  13. 1 1
      tools/paddle
  14. 29 6
      tools/protoc.js
  15. 16 1
      tools/pytorch
  16. 1 1
      tools/sentencepiece
  17. 2 2
      tools/tf
  18. 1 1
      tools/uff
  19. 1 1
      tools/xmodel

+ 1 - 1
package.js

@@ -536,7 +536,7 @@ const update = async () => {
     const targets = process.argv.length > 3 ? process.argv.slice(3) : [
         'armnn',
         'bigdl',
-        'caffe', 'caffe2', 'circle', 'cntk', 'coreml',
+        'caffe', 'circle', 'cntk', 'coreml',
         'dlc', 'dnn',
         'gguf',
         'kann', 'keras',

+ 476 - 0
source/pytorch-proto.js

@@ -0,0 +1,476 @@
+
+export const torch = {};
+export const caffe2 = {};
+
+torch.RecordRef = class RecordRef {
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+torch.RecordRef.prototype.key = "";
+
+torch.TensorDef = class TensorDef {
+
+    constructor() {
+        this.dims = [];
+        this.strides = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+torch.TensorDef.prototype.offset = 0n;
+torch.TensorDef.prototype.requires_grad = false;
+torch.TensorDef.prototype.data_type = 0;
+torch.TensorDef.prototype.data = null;
+torch.TensorDef.prototype.device = "";
+torch.TensorDef.prototype.is_quantized = false;
+torch.TensorDef.prototype.scale = 0;
+torch.TensorDef.prototype.zero_point = 0n;
+
+torch.AttributeDef = class AttributeDef {
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+torch.AttributeDef.prototype.type = "";
+torch.AttributeDef.prototype.name = "";
+torch.AttributeDef.prototype.id = 0n;
+
+torch.ParameterDef = class ParameterDef {
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+torch.ParameterDef.prototype.is_buffer = false;
+torch.ParameterDef.prototype.tensor_id = 0n;
+torch.ParameterDef.prototype.name = "";
+
+torch.ModuleDef = class ModuleDef {
+
+    constructor() {
+        this.submodules = [];
+        this.caffe2_nets = [];
+        this.parameters = [];
+        this.attributes = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+torch.ModuleDef.prototype.torchscript_arena = null;
+torch.ModuleDef.prototype.pickle_arena = null;
+torch.ModuleDef.prototype.cpp_arena = null;
+torch.ModuleDef.prototype.name = "";
+torch.ModuleDef.prototype.optimize = false;
+torch.ModuleDef.prototype.get_state_attribute_id = 0n;
+torch.ModuleDef.prototype.torchscript_debug_arena = null;
+
+torch.LibDef = class LibDef {
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+torch.LibDef.prototype.torchscript_arena = null;
+
+torch.ProtoVersion = {
+    "PROTO_VERSION_NEWEST": 6
+};
+
+torch.ModelDef = class ModelDef {
+
+    constructor() {
+        this.tensors = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+torch.ModelDef.prototype.proto_version = 0n;
+torch.ModelDef.prototype.main_module = null;
+torch.ModelDef.prototype.producer_name = "";
+torch.ModelDef.prototype.producer_version = "";
+
+caffe2.TensorProto = class TensorProto {
+
+    constructor() {
+        this.dims = [];
+        this.float_data = [];
+        this.int32_data = [];
+        this.string_data = [];
+        this.double_data = [];
+        this.int64_data = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.TensorProto.prototype.data_type = 1;
+caffe2.TensorProto.prototype.data_format = 0;
+caffe2.TensorProto.prototype.byte_data = new Uint8Array([]);
+caffe2.TensorProto.prototype.raw_data = new Uint8Array([]);
+caffe2.TensorProto.prototype.name = "";
+caffe2.TensorProto.prototype.device_detail = null;
+caffe2.TensorProto.prototype.segment = null;
+
+caffe2.TensorProto.DataType = {
+    "UNDEFINED": 0,
+    "FLOAT": 1,
+    "INT32": 2,
+    "BYTE": 3,
+    "STRING": 4,
+    "BOOL": 5,
+    "UINT8": 6,
+    "INT8": 7,
+    "UINT16": 8,
+    "INT16": 9,
+    "INT64": 10,
+    "FLOAT16": 12,
+    "DOUBLE": 13,
+    "ZERO_COLLISION_HASH": 14,
+    "REBATCHING_BUFFER": 15
+};
+
+caffe2.TensorProto.SerializationFormat = {
+    "FMT_PROTOBUF": 0,
+    "FMT_BFLOAT16": 1
+};
+
+caffe2.TensorProto.Segment = class Segment {
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.TensorProto.Segment.prototype.begin = 0n;
+caffe2.TensorProto.Segment.prototype.end = 0n;
+
+caffe2.QTensorProto = class QTensorProto {
+
+    constructor() {
+        this.dims = [];
+        this.data = [];
+        this.scales = [];
+        this.biases = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.QTensorProto.prototype.precision = 0;
+caffe2.QTensorProto.prototype.scale = 0;
+caffe2.QTensorProto.prototype.bias = 0;
+caffe2.QTensorProto.prototype.is_signed = false;
+caffe2.QTensorProto.prototype.name = "";
+caffe2.QTensorProto.prototype.data_type = 2;
+caffe2.QTensorProto.prototype.axis = 0;
+caffe2.QTensorProto.prototype.is_multiparam = false;
+
+caffe2.TensorProtos = class TensorProtos {
+
+    constructor() {
+        this.protos = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.TensorShape = class TensorShape {
+
+    constructor() {
+        this.dims = [];
+        this.unknown_dims = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.TensorShape.prototype.data_type = 1;
+caffe2.TensorShape.prototype.unknown_shape = false;
+caffe2.TensorShape.prototype.name = "";
+
+caffe2.TensorShapes = class TensorShapes {
+
+    constructor() {
+        this.shapes = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.TensorBoundShape = class TensorBoundShape {
+
+    constructor() {
+        this.dim_type = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.TensorBoundShape.prototype.shape = null;
+caffe2.TensorBoundShape.prototype.name = "";
+caffe2.TensorBoundShape.prototype.shape_is_final = false;
+
+caffe2.TensorBoundShape.DimType = {
+    "UNKNOWN": 0,
+    "CONSTANT": 1,
+    "BATCH": 2,
+    "BATCH_OF_FEATURE_MAX": 3,
+    "BATCH_OF_FEATURE_MAX_DEFAULT": 4,
+    "FEATURE_MAX": 5,
+    "FEATURE_MAX_DEFAULT": 6
+};
+
+caffe2.TensorBoundShapes = class TensorBoundShapes {
+
+    constructor() {
+        this.shapes = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.TensorBoundShapes.prototype.max_batch_size = 0n;
+caffe2.TensorBoundShapes.prototype.max_feature_len = 0n;
+
+caffe2.AOTConfig = class AOTConfig {
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.AOTConfig.prototype.max_batch_size = 0n;
+caffe2.AOTConfig.prototype.max_seq_size = 0n;
+caffe2.AOTConfig.prototype.in_batch_broadcast = false;
+caffe2.AOTConfig.prototype.onnxifi_blacklist_ops = "";
+caffe2.AOTConfig.prototype.onnxifi_min_ops = 0;
+
+caffe2.Argument = class Argument {
+
+    constructor() {
+        this.floats = [];
+        this.ints = [];
+        this.strings = [];
+        this.tensors = [];
+        this.nets = [];
+        this.qtensors = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.Argument.prototype.name = "";
+caffe2.Argument.prototype.f = 0;
+caffe2.Argument.prototype.i = 0n;
+caffe2.Argument.prototype.s = new Uint8Array([]);
+caffe2.Argument.prototype.t = null;
+caffe2.Argument.prototype.n = null;
+
+caffe2.DeviceTypeProto = {
+    "PROTO_CPU": 0,
+    "PROTO_CUDA": 1,
+    "PROTO_MKLDNN": 2,
+    "PROTO_OPENGL": 3,
+    "PROTO_OPENCL": 4,
+    "PROTO_IDEEP": 5,
+    "PROTO_HIP": 6,
+    "PROTO_FPGA": 7,
+    "PROTO_MAIA": 8,
+    "PROTO_XLA": 9,
+    "PROTO_MPS": 10,
+    "PROTO_COMPILE_TIME_MAX_DEVICE_TYPES": 11
+};
+
+caffe2.DeviceOption = class DeviceOption {
+
+    constructor() {
+        this.extra_info = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.DeviceOption.prototype.device_type = 0;
+caffe2.DeviceOption.prototype.device_id = 0;
+caffe2.DeviceOption.prototype.random_seed = 0;
+caffe2.DeviceOption.prototype.node_name = "";
+caffe2.DeviceOption.prototype.numa_node_id = 0;
+
+caffe2.OperatorDef = class OperatorDef {
+
+    constructor() {
+        this.input = [];
+        this.output = [];
+        this.arg = [];
+        this.control_input = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.OperatorDef.prototype.name = "";
+caffe2.OperatorDef.prototype.type = "";
+caffe2.OperatorDef.prototype.device_option = null;
+caffe2.OperatorDef.prototype.engine = "";
+caffe2.OperatorDef.prototype.is_gradient_op = false;
+caffe2.OperatorDef.prototype.debug_info = "";
+caffe2.OperatorDef.prototype.domain = "";
+caffe2.OperatorDef.prototype.op_version = 0n;
+
+caffe2.MapFieldEntry = class MapFieldEntry {
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.MapFieldEntry.prototype.key = "";
+caffe2.MapFieldEntry.prototype.val = "";
+
+caffe2.BackendOptions = class BackendOptions {
+
+    constructor() {
+        this.option = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.BackendOptions.prototype.backend_name = "";
+
+caffe2.PartitionInfo = class PartitionInfo {
+
+    constructor() {
+        this.device_id = [];
+        this.backend_options = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.PartitionInfo.prototype.name = "";
+caffe2.PartitionInfo.prototype.extra_info = "";
+
+caffe2.NetDef = class NetDef {
+
+    constructor() {
+        this.op = [];
+        this.arg = [];
+        this.external_input = [];
+        this.external_output = [];
+        this.partition_info = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.NetDef.prototype.name = "";
+caffe2.NetDef.prototype.type = "";
+caffe2.NetDef.prototype.num_workers = 0;
+caffe2.NetDef.prototype.device_option = null;
+
+caffe2.ExecutionStep = class ExecutionStep {
+
+    constructor() {
+        this.substep = [];
+        this.network = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.ExecutionStep.prototype.name = "";
+caffe2.ExecutionStep.prototype.num_iter = 0n;
+caffe2.ExecutionStep.prototype.criteria_network = "";
+caffe2.ExecutionStep.prototype.report_net = "";
+caffe2.ExecutionStep.prototype.report_interval = 0;
+caffe2.ExecutionStep.prototype.run_every_ms = 0n;
+caffe2.ExecutionStep.prototype.concurrent_substeps = false;
+caffe2.ExecutionStep.prototype.should_stop_blob = "";
+caffe2.ExecutionStep.prototype.only_once = false;
+caffe2.ExecutionStep.prototype.create_workspace = false;
+caffe2.ExecutionStep.prototype.num_concurrent_instances = 0;
+
+caffe2.PlanDef = class PlanDef {
+
+    constructor() {
+        this.network = [];
+        this.execution_step = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.PlanDef.prototype.name = "";
+
+caffe2.BlobProto = class BlobProto {
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.BlobProto.prototype.name = "";
+caffe2.BlobProto.prototype.type = "";
+caffe2.BlobProto.prototype.tensor = null;
+caffe2.BlobProto.prototype.content = new Uint8Array([]);
+caffe2.BlobProto.prototype.qtensor = null;
+caffe2.BlobProto.prototype.content_num_chunks = 0;
+caffe2.BlobProto.prototype.content_chunk_id = 0;
+
+caffe2.DBReaderProto = class DBReaderProto {
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.DBReaderProto.prototype.name = "";
+caffe2.DBReaderProto.prototype.source = "";
+caffe2.DBReaderProto.prototype.db_type = "";
+caffe2.DBReaderProto.prototype.key = "";
+
+caffe2.BlobSerializationOptions = class BlobSerializationOptions {
+
+    static decodeJson(/* reader */) {
+    }
+};
+
+caffe2.BlobSerializationOptions.prototype.blob_name_regex = "";
+caffe2.BlobSerializationOptions.prototype.chunk_size = 0n;
+caffe2.BlobSerializationOptions.prototype.float_format = 0;
+
+caffe2.BlobSerializationOptions.FloatFormat = {
+    "FLOAT_DEFAULT": 0,
+    "FLOAT_PROTOBUF": 1,
+    "FLOAT_BFLOAT16": 2
+};
+
+caffe2.SerializationOptions = class SerializationOptions {
+
+    constructor() {
+        this.options = [];
+    }
+
+    static decodeJson(/* reader */) {
+    }
+};

+ 1 - 1
tools/bigdl

@@ -17,7 +17,7 @@ sync() {
 schema() {
     echo "bigdl schema"
     [[ $(grep -U $'\x0D' ./source/bigdl-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --root bigdl --out ./source/bigdl-proto.js ./third_party/source/bigdl/spark/dl/src/main/resources/serialization/bigdl.proto
+    node ./tools/protoc.js --binary --root bigdl --out ./source/bigdl-proto.js ./third_party/source/bigdl/spark/dl/src/main/resources/serialization/bigdl.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/bigdl-proto.js ./source/bigdl-proto.js
     fi

+ 1 - 1
tools/caffe

@@ -20,7 +20,7 @@ schema() {
     [[ $(grep -U $'\x0D' ./source/caffe-proto.js) ]] && crlf=1
     temp=$(mktemp -d)
     node ./tools/caffe-script.js ./third_party/source/caffe/src/caffe/proto/caffe.proto ${temp}/caffe.proto
-    node ./tools/protoc.js --text --root caffe --out ./source/caffe-proto.js ${temp}/caffe.proto
+    node ./tools/protoc.js --binary --text --root caffe --out ./source/caffe-proto.js ${temp}/caffe.proto
     rm -rf ${temp}
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/caffe-proto.js ./source/caffe-proto.js

+ 0 - 38
tools/caffe2

@@ -1,38 +0,0 @@
-#!/bin/bash
-
-set -e
-pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
-
-case "${OSTYPE}" in
-    msys*) python="winpty python";;
-    *) python="python";;
-esac
-
-clean() {
-    echo "caffe2 clean"
-    rm -rf "./third_party/source/caffe2"
-}
-
-sync() {
-    echo "caffe2 sync"
-    mkdir -p "./third_party/source/caffe2/proto"
-    curl --silent --location --output "./third_party/source/caffe2/proto/caffe2.proto" "https://github.com/pytorch/pytorch/raw/ff8042bcfb518127c86ad5b4af4fa9171a499904/caffe2/proto/caffe2.proto"
-}
-
-schema() {
-    [[ $(grep -U $'\x0D' ./source/caffe2-proto.js) ]] && crlf=1
-    echo "caffe2 schema"
-    node ./tools/protoc.js --text --root caffe2 --out ./source/caffe2-proto.js ./third_party/source/caffe2/proto/caffe2.proto
-    if [[ -n ${crlf} ]]; then
-        unix2dos --quiet --newfile ./source/caffe2-proto.js ./source/caffe2-proto.js
-    fi
-}
-
-while [ "$#" != 0 ]; do
-    command="$1" && shift
-    case "${command}" in
-        "clean") clean;;
-        "sync") sync;;
-        "schema") schema;;
-    esac
-done

+ 1 - 1
tools/cntk

@@ -17,7 +17,7 @@ sync() {
 schema() {
     echo "cntk schema"
     [[ $(grep -U $'\x0D' ./source/cntk-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --root cntk --out ./source/cntk-proto.js ./third_party/source/cntk/Source/CNTKv2LibraryDll/proto/CNTK.proto
+    node ./tools/protoc.js --binary --root cntk --out ./source/cntk-proto.js ./third_party/source/cntk/Source/CNTKv2LibraryDll/proto/CNTK.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/cntk-proto.js ./source/cntk-proto.js
     fi

+ 1 - 1
tools/coreml

@@ -33,7 +33,7 @@ sync() {
 schema() {
     echo "coreml schema"
     [[ $(grep -U $'\x0D' ./source/coreml-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --text --root coreml --out ./source/coreml-proto.js --path ./third_party/source/coremltools/mlmodel/format Model.proto
+    node ./tools/protoc.js --binary --text --root coreml --out ./source/coreml-proto.js --path ./third_party/source/coremltools/mlmodel/format Model.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/coreml-proto.js ./source/coreml-proto.js
     fi

+ 1 - 1
tools/dnn

@@ -6,7 +6,7 @@ pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 schema() {
     echo "dnn schema"
     [[ $(grep -U $'\x0D' ./source/dnn-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --root dnn --out ./source/dnn-proto.js ./tools/dnn.proto
+    node ./tools/protoc.js --binary --root dnn --out ./source/dnn-proto.js ./tools/dnn.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/dnn-proto.js ./source/dnn-proto.js
     fi

+ 1 - 1
tools/mediapipe

@@ -43,7 +43,7 @@ sync() {
 schema() {
     echo "mediapipe schema"
     [[ $(grep -U $'\x0D' ./source/mediapipe-proto.js) ]] && crlf=1
-    node ./tools/protoc.js  --text --root mediapipe --out ./source/mediapipe-proto.js --path ./third_party/source/mediapipe --path ./third_party/source/tensorflow \
+    node ./tools/protoc.js --text --root mediapipe --out ./source/mediapipe-proto.js --path ./third_party/source/mediapipe --path ./third_party/source/tensorflow \
         mediapipe/framework/calculator.proto \
         mediapipe/calculators/core/packet_resampler_calculator.proto \
         mediapipe/calculators/image/image_cropping_calculator.proto \

+ 1 - 1
tools/nnabla

@@ -49,7 +49,7 @@ schema() {
     ${python} ./tools/nnabla_script.py schema
     deactivate
     [[ $(grep -U $'\x0D' ./source/nnabla-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --text --root nnabla --out ./source/nnabla-proto.js ./third_party/source/nnabla/src/nbla/proto/nnabla.proto
+    node ./tools/protoc.js --binary --text --root nnabla --out ./source/nnabla-proto.js ./third_party/source/nnabla/src/nbla/proto/nnabla.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/nnabla-proto.js ./source/nnabla-proto.js
     fi

+ 1 - 1
tools/om

@@ -12,7 +12,7 @@ schema() {
     echo "om schema"
     [[ $(grep -U $'\x0D' ./source/om-proto.js) ]] && crlf=1
     # https://github.com/Ascend/parser/blob/development/parser/proto/ge_ir.proto
-    node ./tools/protoc.js --text --root om --out ./source/om-proto.js ./tools/om.proto
+    node ./tools/protoc.js --binary --text --root om --out ./source/om-proto.js ./tools/om.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/om-proto.js ./source/om-proto.js
     fi

+ 1 - 1
tools/onnx

@@ -100,7 +100,7 @@ install() {
 schema() {
     echo "onnx schema"
     [[ $(grep -U $'\x0D' ./source/onnx-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --text --root onnx --out ./source/onnx-proto.js --path ./third_party/source/onnx onnx/onnx-ml.proto onnx/onnx-operators-ml.proto
+    node ./tools/protoc.js --binary --text --root onnx --out ./source/onnx-proto.js --path ./third_party/source/onnx onnx/onnx-ml.proto onnx/onnx-operators-ml.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/onnx-proto.js ./source/onnx-proto.js
     fi

+ 1 - 1
tools/paddle

@@ -21,7 +21,7 @@ sync() {
 schema() {
     echo "paddle schema"
     [[ $(grep -U $'\x0D' ./source/paddle-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --root paddle --text --out ./source/paddle-proto.js ./third_party/source/paddle/paddle/fluid/framework/framework.proto
+    node ./tools/protoc.js --binary --root paddle --text --out ./source/paddle-proto.js ./third_party/source/paddle/paddle/fluid/framework/framework.proto
     node ./tools/flatc.js --text --root paddlelite --out ./source/paddle-schema.js ./third_party/source/paddle-lite/lite/model_parser/flatbuffers/param.fbs
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/paddle-proto.js ./source/paddle-proto.js

+ 29 - 6
tools/protoc.js

@@ -1131,9 +1131,9 @@ protoc.Tokenizer = class {
 
 protoc.Generator = class {
 
-    constructor(root, text) {
+    constructor(root, options) {
         this._root = root;
-        this._text = text;
+        this._options = options;
         this._builder = new protoc.Generator.StringBuilder();
         const scopes = Array.from(this._root.children.values()).map((child) => child.fullName);
         const exports = new Set(scopes.map((scope) => scope.split('.')[0]));
@@ -1206,14 +1206,21 @@ protoc.Generator = class {
             /* eslint-enable indent */
         }
 
-        this._builder.add('');
-        this._buildDecodeFunction(type);
+        if (this._options.binary) {
+            this._builder.add('');
+            this._buildDecodeFunction(type);
+        }
 
-        if (this._text) {
+        if (this._options.text) {
             this._builder.add('');
             this._buildDecodeTextFunction(type);
         }
 
+        if (this._options.json) {
+            this._builder.add('');
+            this._buildDecodeJsonFunction(type);
+        }
+
         this._builder.outdent();
         this._builder.add('};');
 
@@ -1412,6 +1419,16 @@ protoc.Generator = class {
         /* eslint-enable indent */
     }
 
+    _buildDecodeJsonFunction() {
+        // /* eslint-disable indent */
+        this._builder.add('static decodeJson(/* reader */) {');
+        this._builder.indent();
+
+        this._builder.outdent();
+        this._builder.add('}');
+        // /* eslint-enable indent */
+    }
+
     static _isKeyword(name) {
         return /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.test(name);
     }
@@ -1486,9 +1503,15 @@ const main = async (args) => {
             case '--root':
                 options.root = args.shift();
                 break;
+            case '--binary':
+                options.binary = true;
+                break;
             case '--text':
                 options.text = true;
                 break;
+            case '--json':
+                options.json = true;
+                break;
             case '--path':
                 options.paths.push(args.shift());
                 break;
@@ -1504,7 +1527,7 @@ const main = async (args) => {
     try {
         const root = new protoc.Root(options.root);
         await root.load(options.paths, options.files);
-        const generator = new protoc.Generator(root, options.text);
+        const generator = new protoc.Generator(root, options);
         if (options.out) {
             await fs.writeFile(options.out, generator.content, 'utf-8');
         }

+ 16 - 1
tools/pytorch

@@ -20,6 +20,7 @@ venv() {
 
 clean() {
     echo "pytorch clean"
+    rm -rf "./third_party/source/caffe2"
     rm -rf "./third_party/source/pytorch"
     rm -rf "./third_party/source/executorch/schema"
 }
@@ -31,6 +32,9 @@ sync() {
     mkdir -p "./third_party/source/executorch/schema"
     curl --silent --location --output "./third_party/source/executorch/schema/scalar_type.fbs" "https://github.com/pytorch/executorch/raw/main/schema/scalar_type.fbs"
     curl --silent --location --output "./third_party/source/executorch/schema/program.fbs" "https://github.com/pytorch/executorch/raw/main/schema/program.fbs"
+    mkdir -p "./third_party/source/caffe2/proto"
+    curl --silent --location --output "./third_party/source/caffe2/proto/caffe2.proto" "https://github.com/pytorch/pytorch/raw/5e69e11d098a2cfccc8a59377c431e9c71cab9a8/caffe2/proto/caffe2.proto"
+    curl --silent --location --output "./third_party/source/caffe2/proto/torch.proto" "https://github.com/pytorch/pytorch/raw/5e69e11d098a2cfccc8a59377c431e9c71cab9a8/caffe2/proto/torch.proto"
 }
 
 install() {
@@ -44,12 +48,23 @@ install() {
 
 
 schema() {
-    [[ $(grep -U $'\x0D' ./source/pytorch-schema.js) ]] && crlf=1
     echo "pytorch schema"
+    [[ $(grep -U $'\x0D' ./source/caffe2-proto.js) ]] && crlf=1
+    node ./tools/protoc.js --binary --text --root caffe2 --out ./source/caffe2-proto.js ./third_party/source/caffe2/proto/caffe2.proto
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./source/caffe2-proto.js ./source/caffe2-proto.js
+    fi
+    [[ $(grep -U $'\x0D' ./source/pytorch-proto.js) ]] && crlf=1
+    node ./tools/protoc.js --json --root pytorch --out ./source/pytorch-proto.js --path ./third_party/source ./third_party/source/caffe2/proto/torch.proto
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./source/pytorch-proto.js ./source/pytorch-proto.js
+    fi
+    [[ $(grep -U $'\x0D' ./source/pytorch-schema.js) ]] && crlf=1
     node ./tools/flatc.js --root torch --out ./source/pytorch-schema.js ./third_party/source/pytorch/torch/csrc/jit/serialization/mobile_bytecode.fbs ./third_party/source/executorch/schema/program.fbs
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/pytorch-schema.js ./source/pytorch-schema.js
     fi
+
 }
 
 metadata() {

+ 1 - 1
tools/sentencepiece

@@ -23,7 +23,7 @@ sync() {
 schema() {
     echo "sentencepiece schema"
     [[ $(grep -U $'\x0D' ./source/sentencepiece-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --text --root sentencepiece --out ./source/sentencepiece-proto.js --path ./third_party/source/sentencepiece src/sentencepiece_model.proto
+    node ./tools/protoc.js --binary --text --root sentencepiece --out ./source/sentencepiece-proto.js --path ./third_party/source/sentencepiece src/sentencepiece_model.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/sentencepiece-proto.js ./source/sentencepiece-proto.js
     fi

+ 2 - 2
tools/tf

@@ -44,7 +44,7 @@ install() {
 schema() {
     echo "tf schema"
     [[ $(grep -U $'\x0D' ./source/tf-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --text --root tf --out ./source/tf-proto.js --path ./third_party/source/tensorflow --path ./third_party/source/tensorflow/third_party/xla tensorflow/core/protobuf/saved_model.proto tensorflow/core/protobuf/tensor_bundle.proto tensorflow/core/util/saved_tensor_slice.proto tensorflow/core/util/event.proto tensorflow/core/protobuf/config.proto tensorflow/core/util/memmapped_file_system.proto tensorflow/core/protobuf/fingerprint.proto
+    node ./tools/protoc.js --binary --text --root tf --out ./source/tf-proto.js --path ./third_party/source/tensorflow --path ./third_party/source/tensorflow/third_party/xla tensorflow/core/protobuf/saved_model.proto tensorflow/core/protobuf/tensor_bundle.proto tensorflow/core/util/saved_tensor_slice.proto tensorflow/core/util/event.proto tensorflow/core/protobuf/config.proto tensorflow/core/util/memmapped_file_system.proto tensorflow/core/protobuf/fingerprint.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/tf-proto.js ./source/tf-proto.js
     fi
@@ -58,7 +58,7 @@ schema() {
     fi
     echo "keras schema"
     [[ $(grep -U $'\x0D' ./source/keras-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --text --root tf --out ./source/keras-proto.js --path ./third_party/source/tensorflow --path ./third_party/source/tensorflow/third_party/xla/third_party/tsl tensorflow/python/keras/protobuf/saved_metadata.proto
+    node ./tools/protoc.js --binary --text --root tf --out ./source/keras-proto.js --path ./third_party/source/tensorflow --path ./third_party/source/tensorflow/third_party/xla/third_party/tsl tensorflow/python/keras/protobuf/saved_metadata.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/keras-proto.js ./source/keras-proto.js
     fi

+ 1 - 1
tools/uff

@@ -6,7 +6,7 @@ pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 schema() {
     echo "uff schema"
     [[ $(grep -U $'\x0D' ./source/uff-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --text --root uff --out ./source/uff-proto.js ./tools/uff.proto
+    node ./tools/protoc.js --binary --text --root uff --out ./source/uff-proto.js ./tools/uff.proto
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/uff-proto.js ./source/uff-proto.js
     fi

+ 1 - 1
tools/xmodel

@@ -19,7 +19,7 @@ sync() {
 schema() {
     echo "xmodel schema"
     [[ $(grep -U $'\x0D' ./source/xmodel-proto.js) ]] && crlf=1
-    node ./tools/protoc.js --text --root xmodel --out ./source/xmodel-proto.js ./third_party/source/xmodel/src/vai_library/usefultools/src/xir_graph_proto_v2.proto
+    node ./tools/protoc.js --binary --text --root xmodel --out ./source/xmodel-proto.js ./third_party/source/xmodel/src/vai_library/usefultools/src/xir_graph_proto_v2.proto
     rm -rf ${temp}
     if [[ -n ${crlf} ]]; then
         unix2dos --quiet --newfile ./source/xmodel-proto.js ./source/xmodel-proto.js