# Copyright (c) 2021, NVIDIA CORPORATION.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: "wenet"
backend: "python"
max_batch_size: 512

sequence_batching{
    max_sequence_idle_microseconds: 5000000
    oldest {
      max_candidate_sequences: 1024
      preferred_batch_size: [32, 64, 128, 256]
    }
    control_input [
        {
            name: "START",
            control [
                {
                    kind: CONTROL_SEQUENCE_START
                    fp32_false_true: [0, 1]
                }
            ]
        },
        {
            name: "READY"
            control [
                {
                    kind: CONTROL_SEQUENCE_READY
                    fp32_false_true: [0, 1]
                }
            ]
        },
        {
            name: "CORRID",
            control [
                {
                    kind: CONTROL_SEQUENCE_CORRID
                    data_type: TYPE_UINT64
                }
            ]
        },
        {
            name: "END",
            control [
                {
                    kind: CONTROL_SEQUENCE_END
                    fp32_false_true: [0, 1]
                }
            ]
        }
    ]
}

parameters [
  {
    key: "beam_size",
    value: { string_value: "#beam_size" }
  },
  {
    key: "cutoff_prob",
    value: { string_value: "0.9999" }
  },
  {
    key: "alpha",
    value: { string_value: "2" }
  },
  {
    key: "beta",
    value: { string_value: "1" }
  },
  {
    key: "vocab_path",
    value: { string_value: "/ws/onnx_model/units.txt"}
  },
  {
    key: "lm_path",
    value: { string_value: "/ws/onnx_model/lm.bin"}
  },
  {
    key: "bidecoder",
    value: { string_value: "#bidecoder"}
  },
  {
    key: "rescoring",
    value: { string_value: "1" }
  },
  {
   key: "FORCE_CPU_ONLY_INPUT_TENSORS",
   value: {string_value:"yes"}
  }
]

input [
   {
    name: "log_probs"
    data_type: TYPE_#DTYPE
    dims: [-1, #beam_size] # [-1, beam_size]
  },
  {
    name: "log_probs_idx"
    data_type: TYPE_INT64
    dims: [-1, #beam_size] # [-1, beam_size]
  },
  {
    name: "chunk_out"
    data_type: TYPE_#DTYPE
    dims: [-1, -1]
  },
  {
    name: "chunk_out_lens"
    data_type: TYPE_INT32
    dims: [1]
  }
]
output [
  {
    name: "OUTPUT0"
    data_type: TYPE_STRING
    dims: [1]
    reshape { shape: [] }
  }
]
instance_group [
    {
      count: 2
      kind: KIND_CPU
    }
]
