package caisar

  1. Overview
  2. Docs

Tensors

A serialized tensor value.

module DataType : sig ... end
module DataLocation : sig ... end

Location of the data for this tensor. MUST be one of:

module Segment : sig ... end

For very large tensors, we may want to store them in chunks, in which case the following fields will specify the segment that is stored in the current TensorProto.

type t = {
  1. dims : int64 list;
    (*

    The shape of the tensor.

    *)
  2. data_type : int option;
    (*

    The data type of the tensor. This field MUST have a valid TensorProto.DataType value

    *)
  3. segment : Segment.t option;
  4. float_data : float list;
    (*

    For float and complex64 values Complex64 tensors are encoded as a single array of floats, with the real components appearing in odd numbered positions, and the corresponding imaginary component appearing in the subsequent even numbered position. (e.g., [1.0 + 2.0i, 3.0 + 4.0i] is encoded as [1.0, 2.0 ,3.0 ,4.0] When this field is present, the data_type field MUST be FLOAT or COMPLEX64.

    *)
  5. int32_data : int list;
    (*

    For int32, uint8, int8, uint16, int16, bool, and float16 values float16 values must be bit-wise converted to an uint16_t prior to writing to the buffer. When this field is present, the data_type field MUST be INT32, INT16, INT8, UINT16, UINT8, BOOL, or FLOAT16

    *)
  6. string_data : bytes list;
    (*

    For strings. Each element of string_data is a UTF-8 encoded Unicode string. No trailing null, no leading BOM. The protobuf "string" scalar type is not used to match ML community conventions. When this field is present, the data_type field MUST be STRING

    *)
  7. int64_data : int64 list;
    (*

    For int64. When this field is present, the data_type field MUST be INT64

    *)
  8. name : string option;
    (*

    Optionally, a name for the tensor.

    namespace Value

    *)
  9. raw_data : bytes option;
    (*

    Serializations can either use one of the fields above, or use this raw bytes field. The only exception is the string case, where one is required to store the content in the repeated bytes string_data field.

    When this raw_data field is used to store tensor value, elements MUST be stored in as fixed-width, little-endian order. Floating-point data types MUST be stored in IEEE 754 format. Complex64 elements must be written as two consecutive FLOAT values, real component first. Complex128 elements must be written as two consecutive DOUBLE values, real component first. Boolean type MUST be written one byte per tensor element (00000001 for true, 00000000 for false).

    Note: the advantage of specific field rather than the raw_data field is that in some cases (e.g. int data), protobuf does a better packing via variable length storage, and may lead to smaller binary footprint. When this field is present, the data_type field MUST NOT be STRING or UNDEFINED

    *)
  10. double_data : float list;
    (*

    For double Complex128 tensors are encoded as a single array of doubles, with the real components appearing in odd numbered positions, and the corresponding imaginary component appearing in the subsequent even numbered position. (e.g., [1.0 + 2.0i, 3.0 + 4.0i] is encoded as [1.0, 2.0 ,3.0 ,4.0] When this field is present, the data_type field MUST be DOUBLE or COMPLEX128

    *)
  11. uint64_data : int64 list;
    (*

    For uint64 and uint32 values When this field is present, the data_type field MUST be UINT32 or UINT64

    *)
  12. doc_string : string option;
    (*

    A human-readable documentation for this tensor. Markdown is allowed.

    *)
  13. external_data : StringStringEntryProto.t list;
    (*

    Data can be stored inside the protobuf file using type-specific fields or raw_data. Alternatively, raw bytes data can be stored in an external file, using the external_data field. external_data stores key-value pairs describing data location. Recognized keys are:

    • "location" (required) - POSIX filesystem path relative to the directory where the ONNX protobuf model was stored
    • "offset" (optional) - position of byte at which stored data begins. Integer stored as string. Offset values SHOULD be multiples 4096 (page size) to enable mmap support.
    • "length" (optional) - number of bytes containing data. Integer stored as string.
    • "checksum" (optional) - SHA1 digest of file specified in under 'location' key.
    *)
  14. data_location : DataLocation.t option;
    (*

    If value not set, data is stored in raw_data (if set) otherwise in type-specified field.

    *)
}
val make : ?dims:int64 list -> ?data_type:int -> ?segment:Segment.t -> ?float_data:float list -> ?int32_data:int list -> ?string_data:bytes list -> ?int64_data:int64 list -> ?name:string -> ?raw_data:bytes -> ?double_data:float list -> ?uint64_data:int64 list -> ?doc_string:string -> ?external_data:StringStringEntryProto.t list -> ?data_location:DataLocation.t -> unit -> t

Helper function to generate a message using default values

Serialize the message to binary format

Deserialize from binary format

Serialize to Json (compatible with Yojson.Basic.t)

Deserialize from Json (compatible with Yojson.Basic.t)

val name : unit -> string

Fully qualified protobuf name of this message

OCaml

Innovation. Community. Security.