modelEvaluateRecurrentNeuralNet

Extends from BaseClasses.BaseRecurrentNeuralNet.

Information

Use this block if you want to include a recurrent neural network in Modelica.

Please place this block in your model and

  • give the path to the TFLite/ONNX model
  • specify the number of inputs
  • specify the sampling interval and how many elements from previous times should be fed into the net
  • provide the values for the input of the block and use the outputs in the same manner as it was done during training

In continuous mode the historic values are generated by a delay. You could choose between the computational improved Clara-Delay and the delay in the Modelica-Standard-Library. If continuous is deactivated the model will create an event when reaching the sampling time - this should be avoided for performance reasons.

As tensorflow lite uses a flattened input array, you have to specify the flattening method. In the standard tensorflow setting you have to use the predefined option OldFirstInputSequential.

The example TF_PI_RNN_tflite uses this block.

TensorFlow Lite FlexOps

To use FlexOps with the TensorFlow Lite runtime, additional dynamic libraries must be provided in the SMArtInt library resources. Follow the steps below:

  1. Copy the appropriate FlexOps library into the corresponding platform folder (win64 or linux64) inside the Resources Library folder:
    • Windows: tensorflowlite_flex.dll
    • Linux: libtensorflowlite_flex.so
  2. Activate TensorFlow Lite FlexOps usage in the model parameter dialog.

CUDA GPU Support for ONNX Runtime

To use ONNX Runtime with GPU acceleration, CUDA must be installed on the operating system (tested with CUDA version 13.0), and a CUDA-compatible GPU must be available. In addition, the required ONNX Runtime GPU provider libraries must be provided in the SMArtInt library resources. Follow the steps below:

  1. Download the ONNX Runtime build with GPU support from:
    ONNX Runtime v1.23.2 Release
  2. Select and extract the appropriate package for your operating system:
    • Windows: onnxruntime-win-x64-gpu-1.23.2.zip
    • Linux: onnxruntime-linux-x64-gpu-1.23.2.tgz
  3. Copy the required provider libraries into the corresponding platform folder (win64 or linux64) inside the Resources Library folder:
    • onnxruntime_providers_cuda.dll / .so
    • onnxruntime_providers_shared.dll / .so
  4. Activate GPU usage in the model parameter dialog.

Parameters

TypeNameDefaultDescription
IntegernInputElements (from BaseNeuralNet)product(inputSizes)
IntegernOutputElements (from BaseNeuralNet)product(outputSizes)
Selected Model
StringpathToAIModel (from BaseNeuralNet)""Choose path to AI model
Tensor sizing
IntegerinputDimensions (from BaseNeuralNet)1Number of input dimension
IntegerinputSizes (from BaseNeuralNet){1}Vector with size of tensor in each dimension
IntegeroutputDimensions (from BaseNeuralNet)1Number of output dimension
IntegeroutputSizes (from BaseNeuralNet){1}Vector with size of tensor in each dimension
RNN Timing Settings
Booleanstateful (from BaseNeuralNet)falseActivate state handling for RNN with state in-/outputs
RealsamplePeriod (from BaseNeuralNet)0Fixed sample period for RNNs
IntegernHistoricElements (from BaseRecurrentNeuralNet)10Number of elements from sampling steps for each input fed to the neural net
Booleancontinuous (from BaseRecurrentNeuralNet)false=true: model operates continuously; input values are delayed
BooleanuseClaRaDelay (from BaseRecurrentNeuralNet)trueUse the ClaRa delay instead of MSL delay
Advanced › Performance
IntegernumberOfThreads (from BaseNeuralNet)1Number of threads used for inference (0: Number of CPU cores)
Advanced › TFLite
BooleanuseFlexOps (from BaseNeuralNet)falseActivate to allow Tensorflow Flex Ops for tflite models
Advanced › ONNX
BooleanuseGPU (from BaseNeuralNet)falseActivate to use a compatible CUDA GPU for inference
IntegergpuDeviceID (from BaseNeuralNet)0CUDA device ID
SMArtInt.Internal.Types.ExecutionModeexecutionMode (from BaseNeuralNet)SMArtInt.Internal.Types.ExecutionMode.SequentialExecution mode for run inference
Input/Output Sizing
IntegernumberOfInputs (from BaseRecurrentNeuralNet)1Number of input values
IntegernumberOfOutputs (from BaseRecurrentNeuralNet)1Number of output values
IntegerbatchSize (from BaseRecurrentNeuralNet)1Number of parallel batched simulations
BooleanreturnSequences (from BaseRecurrentNeuralNet)false

Connectors

TypeNameDefaultDescription
Modelica.Blocks.Interfaces.RealInput[batchSize,numberOfInputs]u
Modelica.Blocks.Interfaces.RealOutput[batchSize,numberOfOutputs]y
Modelica.Blocks.Interfaces.RealOutput[batchSize,numberOfOutputs,nHistoricElements]ySequences

Components

TypeNameDefaultDescription
Internal.Utilities.Dependencies.OnnxGpuDependenciesonnxGpuDependencies (from BaseNeuralNet)
Internal.Utilities.Dependencies.TFFlexOpsDependenciestFFlexOpsDependencies (from BaseNeuralNet)
Internal.Utilities.RunInterferenceRNNrunInterferenceHistory (from BaseRecurrentNeuralNet)