├── .circleci └── config.yml ├── .credo.exs ├── .dialyzerignore ├── .dockerignore ├── .formatter.exs ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── c_src ├── Makefile ├── extensor.cpp ├── extensor.hpp └── tf.cpp ├── coveralls.json ├── docker ├── ubuntu-cpu.dockerfile └── ubuntu-gpu.dockerfile ├── lib ├── extensor │ ├── matrex.ex │ ├── nif.ex │ ├── session.ex │ └── tensor.ex └── tensorflow │ ├── core │ ├── framework │ │ ├── allocation_description.pb.ex │ │ ├── api_def.pb.ex │ │ ├── attr_value.pb.ex │ │ ├── cost_graph.pb.ex │ │ ├── device_attributes.pb.ex │ │ ├── function.pb.ex │ │ ├── graph.pb.ex │ │ ├── graph_transfer_info.pb.ex │ │ ├── kernel_def.pb.ex │ │ ├── log_memory.pb.ex │ │ ├── node_def.pb.ex │ │ ├── op_def.pb.ex │ │ ├── reader_base.pb.ex │ │ ├── remote_fused_graph_execute_info.pb.ex │ │ ├── resource_handle.pb.ex │ │ ├── step_stats.pb.ex │ │ ├── summary.pb.ex │ │ ├── tensor.pb.ex │ │ ├── tensor_description.pb.ex │ │ ├── tensor_shape.pb.ex │ │ ├── tensor_slice.pb.ex │ │ ├── types.pb.ex │ │ ├── variable.pb.ex │ │ └── versions.pb.ex │ └── protobuf │ │ ├── autotuning.pb.ex │ │ ├── bfc_memory_map.pb.ex │ │ ├── cluster.pb.ex │ │ ├── config.pb.ex │ │ ├── control_flow.pb.ex │ │ ├── conv_autotuning.pb.ex │ │ ├── critical_section.pb.ex │ │ ├── debug.pb.ex │ │ ├── debug_event.pb.ex │ │ ├── device_filters.pb.ex │ │ ├── device_properties.pb.ex │ │ ├── eager_service.pb.ex │ │ ├── error_codes.pb.ex │ │ ├── graph_debug_info.pb.ex │ │ ├── master.pb.ex │ │ ├── master_service.pb.ex │ │ ├── meta_graph.pb.ex │ │ ├── named_tensor.pb.ex │ │ ├── queue_runner.pb.ex │ │ ├── remote_tensor_handle.pb.ex │ │ ├── replay_log.pb.ex │ │ ├── rewriter_config.pb.ex │ │ ├── saved_model.pb.ex │ │ ├── saved_object_graph.pb.ex │ │ ├── saver.pb.ex │ │ ├── struct.pb.ex │ │ ├── tensor_bundle.pb.ex │ │ ├── tensorflow_server.pb.ex │ │ ├── trace_events.pb.ex │ │ ├── trackable_object_graph.pb.ex │ │ ├── transport_options.pb.ex │ │ ├── verifier_config.pb.ex │ │ ├── worker.pb.ex │ │ └── worker_service.pb.ex │ └── stream_executor │ └── dnn.pb.ex ├── mix.exs ├── mix.lock ├── priv └── .gitignore └── test ├── data ├── pythagoras.pb └── pythagoras │ └── saved_model.pb ├── extensor ├── matrex_test.exs ├── session_test.exs └── tensor_test.exs ├── pythagoras.py └── test_helper.exs /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: circleci/elixir:1.10 6 | 7 | working_directory: ~/repo 8 | steps: 9 | - checkout 10 | - restore_cache: 11 | keys: 12 | - build-{{checksum "mix.lock"}} 13 | - run: git submodule sync 14 | - run: git submodule update --init 15 | - run: curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.3.1.tar.gz | sudo tar -C /usr/local -xz 16 | - run: sudo apt-get install libatlas-base-dev 17 | - run: sudo ldconfig 18 | - run: mix local.hex --force 19 | - run: mix local.rebar --force 20 | - run: mix deps.get 21 | - run: mix format --check-formatted 22 | - run: mix test 23 | - run: mix credo --strict -i todo 24 | - run: mix dialyzer --halt-exit-status 25 | - run: "[[ -n $COVERALLS_REPO_TOKEN ]] && mix coveralls.post --sha $(git rev-parse HEAD) --branch $(git rev-parse --abbrev-ref HEAD) || true" 26 | - save_cache: 27 | key: build-{{checksum "mix.lock"}} 28 | paths: 29 | - deps 30 | - _build 31 | -------------------------------------------------------------------------------- /.credo.exs: -------------------------------------------------------------------------------- 1 | %{ 2 | configs: [ 3 | %{ 4 | name: "default", 5 | files: %{ 6 | included: ["lib/", "test/"], 7 | excluded: ["lib/tensorflow"] 8 | }, 9 | checks: [ 10 | # this check doesn't work correctly with binary pattern matching <<>> 11 | {Credo.Check.Consistency.SpaceAroundOperators, false} 12 | ] 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.dialyzerignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pylon/extensor/58fa7a06ff952020fedfc5c72f61a0b5a7f7c7bb/.dialyzerignore -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | _build 3 | deps 4 | -------------------------------------------------------------------------------- /.formatter.exs: -------------------------------------------------------------------------------- 1 | [ 2 | inputs: [ 3 | "test/**/*.exs", 4 | "lib/**/*.{ex,exs}", 5 | "mix.exs" 6 | ], 7 | line_length: 78, 8 | ] 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build/ 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover/ 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps/ 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc/ 12 | 13 | # Ignore .fetch files in case you like to edit your project deps locally. 14 | /.fetch 15 | 16 | # If the VM crashes, it generates a dump, let's ignore it too. 17 | erl_crash.dump 18 | 19 | # Also ignore archive artifacts (built via "mix archive.build"). 20 | *.ez 21 | 22 | .idea/ 23 | *.iml 24 | 25 | # Private files 26 | /obj/ 27 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | Contact: support@pylon.com 4 | 5 | ## Why have a Code of Conduct? 6 | 7 | As contributors and maintainers of this project, we are committed to providing a friendly, safe and welcoming environment for all, regardless of age, disability, gender, nationality, race, religion, sexuality, or similar personal characteristic. 8 | 9 | The goal of the Code of Conduct is to specify a baseline standard of behavior so that people with different social values and communication styles can talk about the Extensor project effectively, productively, and respectfully, even in face of disagreements. The Code of Conduct also provides a mechanism for resolving conflicts in the community when they arise. 10 | 11 | ## Our Values 12 | 13 | These are the values project developers should aspire to: 14 | 15 | * Be friendly and welcoming 16 | * Be patient 17 | * Remember that people have varying communication styles and that not everyone is using their native language. (Meaning and tone can be lost in translation.) 18 | * Be thoughtful 19 | * Productive communication requires effort. Think about how your words will be interpreted. 20 | * Remember that sometimes it is best to refrain entirely from commenting. 21 | * Be respectful 22 | * In particular, respect differences of opinion. It is important that we resolve disagreements and differing views constructively. 23 | * Avoid destructive behavior 24 | * Derailing: stay on topic; if you want to talk about something else, start a new conversation. 25 | * Unconstructive criticism: don't merely decry the current state of affairs; offer (or at least solicit) suggestions as to how things may be improved. 26 | * Snarking (pithy, unproductive, sniping comments). 27 | 28 | The following actions are explicitly forbidden: 29 | 30 | * Insulting, demeaning, hateful, or threatening remarks. 31 | * Discrimination based on age, disability, gender, nationality, race, religion, sexuality, or similar personal characteristic. 32 | * Bullying or systematic harassment. 33 | * Unwelcome sexual advances. 34 | * Incitement to any of these. 35 | 36 | ## Where does the Code of Conduct apply? 37 | 38 | If you participate in or contribute to the Extensor project ecosystem in any way, you are encouraged to follow the Code of Conduct while doing so. 39 | 40 | Explicit enforcement of the Code of Conduct applies to the official mediums operated by the Extensor project: 41 | 42 | * The official GitHub projects and code reviews. 43 | 44 | Other project activities (such as conferences, meetups, and other unofficial forums) are encouraged to adopt this Code of Conduct. Such groups must provide their own contact information. 45 | 46 | Project maintainers may remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. 47 | 48 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by emailing: support@pylon.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. **All reports will be kept confidential**. 49 | 50 | **The goal of the Code of Conduct is to resolve conflicts in the most harmonious way possible**. We hope that in most cases issues may be resolved through polite discussion and mutual agreement. Bannings and other forceful measures are to be employed only as a last resort. **Do not** post about the issue publicly or try to rally sentiment against a particular individual or group. 51 | 52 | ## Acknowledgements 53 | 54 | This document was based on the Code of Conduct from the Elixir project. 55 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to contribute to Extensor 2 | Interested in contributing to Extensor? We appreciate all kinds of help! 3 | 4 | ### Pull Requests 5 | We gladly welcome pull requests. 6 | 7 | Before making any changes, we recommend opening an issue (if it doesn’t 8 | already exist) and discussing your proposed changes. This will let us give 9 | you advice on the proposed changes. If the changes are minor, then feel free 10 | to make them without discussion. 11 | 12 | ### Development Process 13 | To make changes, fork the repo. Write code in this fork with the following 14 | guidelines. Some of these checks are performed automatically by CI whenever 15 | a branch is pushed. These automated checks must pass before a PR will be 16 | merged. The checks can also be used in a commit/push hook with the following 17 | script. 18 | 19 | ```bash 20 | mix compile --warnings-as-errors --force || exit 1 21 | mix format --check-formatted || exit 1 22 | mix test || exit 1 23 | mix credo --strict -i todo || exit 1 24 | mix dialyzer --halt-exit-status || exit 1 25 | ``` 26 | 27 | #### Formatting 28 | For better or worse, we use the Elixir formatter. You can run `mix format` 29 | prior to checkin to format your changes. 30 | 31 | #### Static Analysis 32 | Extensor uses the `credo` tool to check consistency and find bugs. You can 33 | run `mix credo --strict` to evaluate these checks. We also use `dialyzer` 34 | for typespec checking. 35 | 36 | #### Test Coverage 37 | We strive to keep test coverage as high as possible using `excoveralls`. 38 | Coverage can be checked by running `mix coveralls.html` for an HTML report. 39 | 40 | #### Native Code 41 | Extensor interfaces with Tensorflow using Erlang Native Interface Functions 42 | (NIFs) written in C++. We don't trust ourselves or anyone else to write 43 | C/C++ safely, so we try to write as little of it as possible. Native code is 44 | subjected to higher scrutiny during review and requires stress tests for 45 | memory leaks and parallelism tests for safety. 46 | 47 | Feel free to contact the maintainers for information on how to do work with 48 | and test the native interface. And if you have ideas on how to improve the 49 | NIF development process, please suggest them! 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Extensor 2 | 3 | Extensor implements [Tensorflow](https://tensorflow.org) bindings for inference 4 | in [Elixir](https://elixir-lang.org/). This library can be used to execute 5 | computation graphs created in Tensorflow on the CPU or GPU. Extensor 6 | provides minimal abstractions over the Tensorflow C library and includes 7 | as little custom native code as possible. These NIFs have been extensively 8 | tested for memory leaks and paralellism safety so that the library can be 9 | relied on for production use. 10 | 11 | ## Status 12 | [![Hex](http://img.shields.io/hexpm/v/extensor.svg?style=flat)](https://hex.pm/packages/extensor) 13 | [![CircleCI](https://circleci.com/gh/pylon/extensor.svg?style=shield)](https://circleci.com/gh/pylon/extensor) 14 | [![Coverage](https://coveralls.io/repos/github/pylon/extensor/badge.svg)](https://coveralls.io/github/pylon/extensor) 15 | 16 | The API reference is available [here](https://hexdocs.pm/extensor/). 17 | 18 | ## Installation 19 | 20 | ### Hex 21 | ```elixir 22 | def deps do 23 | [ 24 | {:extensor, "~> 2.3"} 25 | ] 26 | end 27 | ``` 28 | 29 | ### Dependencies 30 | This project requires the Tensorflow C headers/libraries. For development, 31 | these can be installed by following the [official Tensorflow instructions]( 32 | https://www.tensorflow.org/install/lang_c). 33 | 34 | For docker deployment, see the sample dockerfiles in the docker directory. 35 | Docker for ubuntu can be tested with the following commands. 36 | 37 | ```bash 38 | docker build -t extensor -f docker/ubuntu-cpu.dockerfile . 39 | docker run --rm -it extensor mix test 40 | ``` 41 | 42 | If you have nvidia tools installed, you can test on the GPU by using the 43 | `ubuntu-gpu.dockerfile` and substituting `nvidia-docker` for `docker` above. 44 | 45 | ## Usage 46 | For a simple example, Extensor can be used to evaluate the Pythagorean 47 | identity (c² = a² + b²). The following python [script]( 48 | https://github.com/pylon/extensor/tree/master/test/pythagoras.py) can be used 49 | to create and save a graph that calculates the length of the hypotenuse. 50 | 51 | ```python 52 | import tensorflow as tf 53 | 54 | a = tf.placeholder(tf.float32, name='a') 55 | b = tf.placeholder(tf.float32, name='b') 56 | c = tf.sqrt(tf.add(tf.square(a), tf.square(b)), name='c') 57 | 58 | with tf.Session() as session: 59 | tf.train.write_graph(session.graph_def, 60 | 'test/data', 61 | 'pythagoras.pb', 62 | as_text=False) 63 | ``` 64 | 65 | This model can then be used in Elixir to evaluate the compute graph and 66 | calculate a few hypotenuses. This model file is also available in the repo 67 | under [test/data/pythagoras.pb]( 68 | https://github.com/pylon/extensor/tree/master/test/data/pythagoras.pb). 69 | 70 | ```elixir 71 | session = Extensor.Session.load_frozen_graph!("test/data/pythagoras.pb") 72 | 73 | input = %{ 74 | "a" => Extensor.Tensor.from_list([3, 5]), 75 | "b" => Extensor.Tensor.from_list([4, 12]) 76 | } 77 | 78 | output = Extensor.Session.run!(session, input, ["c"]) 79 | 80 | Extensor.Tensor.to_list(output["c"]) 81 | ``` 82 | 83 | This block should output the list [5.0, 13.0], which corresponds to the 84 | lengths of the hypotenuses of the first two Pythagorean triples. 85 | 86 | ### Model Formats 87 | Extensor supports the frozen [graph_def]( 88 | https://www.tensorflow.org/extend/tool_developers/#graphdef) and [saved_model]( 89 | https://www.tensorflow.org/programmers_guide/saved_model) serialization 90 | formats. 91 | 92 | For example, the Google [Inception](https://github.com/google/inception) 93 | [model](http://download.tensorflow.org/models/inception_v3_2016_08_28.tar.gz) 94 | has its weights frozen to constant tensors, so that it can be loaded directly 95 | from a protobuf via `load_frozen_graph`. 96 | 97 | However, the frozen graph approach may not work for models that contain 98 | unfreezable variables (like RNNs). For these models, Extensor supports the 99 | Tensorflow saved_model format, which is the format used by Tensorflow serving 100 | (TFS). The saved_model format is loaded from a directory path, which includes 101 | model metadata and initial variable weights. These models can be loaded with 102 | `load_saved_model`. 103 | 104 | ### Configuration 105 | Extensor supports passing a [ConfigProto]( 106 | https://www.tensorflow.org/versions/r1.0/api_docs/python/tf/ConfigProto) 107 | object when creating a session for inference configuration. See the 108 | Tensorflow.ConfigProto module for more information on the configuration 109 | data structures. 110 | 111 | ```elixir 112 | config = %{ 113 | Tensorflow.ConfigProto.new() 114 | | gpu_options: %{ 115 | Tensorflow.GPUOptions.new() 116 | | allow_growth: true 117 | } 118 | } 119 | 120 | session = Extensor.Session.load_saved_model!("test/data/pythagoras", config) 121 | ``` 122 | 123 | ### Tensor Format 124 | The previous examples used the tensor from_list/to_list convenience functions 125 | to read/write tensor data. However, any binary tensor data may be used, as 126 | long as it adheres to Tensorflow's [layout]( 127 | https://www.tensorflow.org/performance/xla/shapes) and endianness (native) 128 | conventions. 129 | 130 | In general, a tensor is defined by `type`, `shape`, and `data` parameters. 131 | These can be used to construct an `Extensor.Tensor` struct directly. 132 | 133 | The data `type` is an atom identifying one of the supported tensorflow data 134 | types. 135 | 136 | atom|tensorflow type 137 | -|- 138 | `:float`|`TF_FLOAT` 139 | `:double`|`TF_DOUBLE` 140 | `:int32`|`TF_INT32` 141 | `:uint8`|`TF_UINT8` 142 | `:int16`|`TF_INT16` 143 | `:int8`|`TF_INT8` 144 | `:string`|`TF_STRING` 145 | `:complex64`|`TF_COMPLEX64` 146 | `:complex`|`TF_COMPLEX` 147 | `:int64`|`TF_INT64` 148 | `:bool`|`TF_BOOL` 149 | `:qint8`|`TF_QINT8` 150 | `:quint8`|`TF_QUINT8` 151 | `:qint32`|`TF_QINT32` 152 | `:bfloat16`|`TF_BFLOAT16` 153 | `:qint16`|`TF_QINT16` 154 | `:quint16`|`TF_QUINT16` 155 | `:uint16`|`TF_UINT16` 156 | `:complex128`|`TF_COMPLEX128` 157 | `:half`|`TF_HALF` 158 | `:resource`|`TF_RESOURCE` 159 | `:variant`|`TF_VARIANT` 160 | `:uint32`|`TF_UINT32` 161 | `:uint64`|`TF_UINT64` 162 | 163 | The tensor `shape` is a tuple containing the dimensions of the tensor. The 164 | `data` field contains the binary tensor data, whose size must be consistent 165 | with the tensor shape. The following is an example of a tensor struct. 166 | 167 | ```elixir 168 | %Tensor{ 169 | type: :double, 170 | shape: {2, 1}, 171 | data: <<1::native-float-64, 2::native-float-64>> 172 | } 173 | ``` 174 | 175 | ## Matrex Integration 176 | 177 | Extensor supports optional integration with 178 | [Matrex](https://hexdocs.pm/matrex/Matrex.html). To demonstrate, we'll re-use 179 | our Pythagoras example [test/data/pythagoras.pb]( 180 | https://github.com/pylon/extensor/tree/master/test/data/pythagoras.pb) 181 | 182 | ```elixir 183 | a = Matrex.new([[3, 5], [7, 9]]) 184 | b = Matrex.new([[4, 12], [24, 40]]) 185 | 186 | input = %{ 187 | "a" => Extensor.Matrex.to_tensor(a), 188 | "b" => Extensor.Matrex.to_tensor(b) 189 | } 190 | 191 | session = Extensor.Session.load_frozen_graph!("test/data/pythagoras.pb") 192 | output = Extensor.Session.run!(session, input, ["c"]) 193 | 194 | output |> Map.get("c") |> Extensor.Matrex.from_tensor() 195 | ``` 196 | 197 | This block should output a 2x2 matrix, which corresponds to the 198 | lengths of the hypotenuses of the first four Pythagorean triples. 199 | 200 | ## Development 201 | The Tensorflow protocol buffer wrappers were generated using the 202 | [protobuf-elixir](https://github.com/tony612/protobuf-elixir) library 203 | with the following command, assuming Tensorflow is cloned in the 204 | ../tensorflow directory: 205 | 206 | ```bash 207 | protoc \ 208 | --elixir_out=lib \ 209 | --proto_path=../tensorflow \ 210 | $(ls -1 \ 211 | ../tensorflow/tensorflow/core/framework/*.proto \ 212 | ../tensorflow/tensorflow/core/protobuf/*.proto \ 213 | ../tensorflow/tensorflow/stream_executor/*.proto) 214 | ``` 215 | 216 | ## License 217 | 218 | Copyright 2018 Pylon, Inc. 219 | 220 | Licensed under the Apache License, Version 2.0 (the "License"); 221 | you may not use this file except in compliance with the License. 222 | You may obtain a copy of the License at 223 | 224 | http://www.apache.org/licenses/LICENSE-2.0 225 | 226 | Unless required by applicable law or agreed to in writing, software 227 | distributed under the License is distributed on an "AS IS" BASIS, 228 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 229 | See the License for the specific language governing permissions and 230 | limitations under the License. 231 | -------------------------------------------------------------------------------- /c_src/Makefile: -------------------------------------------------------------------------------- 1 | ERLANG_PATH ?= $(shell erl -eval 'io:format("~s", [lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)])])' -s init stop -noshell) 2 | CC = g++ 3 | CFLAGS = -std=c++11 -Wall -Werror -O3 -fpic \ 4 | -Wl,-undefined,dynamic_lookup -shared \ 5 | -I$(ERLANG_PATH)/include -L$(ERLANG_PATH)/lib 6 | LIBS = -ltensorflow 7 | OBJDIR = ../obj 8 | OUTDIR = ../priv 9 | 10 | all: $(OUTDIR)/extensor.so 11 | 12 | clean: 13 | $(RM) $(OUTDIR)/extensor.so 14 | 15 | rebuild: clean all 16 | 17 | $(OUTDIR)/extensor.so: extensor.cpp tf.cpp 18 | 19 | %.so: 20 | mkdir -p $(dir $@) 21 | $(CC) $(CFLAGS) -o $@ $^ $(LIBS) 22 | 23 | .PHONY: all clean rebuild 24 | -------------------------------------------------------------------------------- /c_src/extensor.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * MODULE: init.cpp 4 | * PURPOSE: nif initialization and export 5 | * 6 | ***************************************************************************/ 7 | /*-------------------[ Pre Include Defines ]-------------------*/ 8 | /*-------------------[ Library Include Files ]-------------------*/ 9 | /*-------------------[ Project Include Files ]-------------------*/ 10 | #include "extensor.hpp" 11 | /*-------------------[ Macros/Constants/Types ]-------------------*/ 12 | #define DECLARE_NIF(name) \ 13 | extern ERL_NIF_TERM nif_##name (ErlNifEnv*, int, const ERL_NIF_TERM[]) 14 | #define EXPORT_NIF(name, args, ...) \ 15 | (ErlNifFunc){ #name, args, nif_##name, __VA_ARGS__ } 16 | /*-------------------[ Global Variables ]-------------------*/ 17 | /*-------------------[ Global Prototypes ]-------------------*/ 18 | extern int nif_tf_init (ErlNifEnv* env); 19 | /*-------------------[ Module Variables ]-------------------*/ 20 | /*-------------------[ Module Prototypes ]-------------------*/ 21 | DECLARE_NIF(tf_load_library); 22 | DECLARE_NIF(tf_parse_frozen_graph); 23 | DECLARE_NIF(tf_load_saved_model); 24 | DECLARE_NIF(tf_run_session); 25 | /*-------------------[ Implementation ]-------------------*/ 26 | // nif function table 27 | static ErlNifFunc nif_map[] = { 28 | EXPORT_NIF(tf_load_library, 1), 29 | EXPORT_NIF(tf_parse_frozen_graph, 2, ERL_NIF_DIRTY_JOB_CPU_BOUND), 30 | EXPORT_NIF(tf_load_saved_model, 3, ERL_NIF_DIRTY_JOB_IO_BOUND), 31 | EXPORT_NIF(tf_run_session, 3, ERL_NIF_DIRTY_JOB_IO_BOUND), 32 | }; 33 | /*-----------< FUNCTION: nif_loaded >---------------------------------------- 34 | // Purpose: nif onload callback 35 | // Parameters: env - erlang environment 36 | // priv_data - return private state via here 37 | // state - nif load parameter 38 | // Returns: 1 if successful 39 | // 0 otherwise 40 | ---------------------------------------------------------------------------*/ 41 | static int nif_loaded (ErlNifEnv* env, void** priv_data, ERL_NIF_TERM state) 42 | { 43 | *priv_data = NULL; 44 | if (!nif_tf_init(env)) 45 | return 1; 46 | return 0; 47 | } 48 | // nif entry point 49 | ERL_NIF_INIT( 50 | Elixir.Extensor.NIF, 51 | nif_map, 52 | &nif_loaded, 53 | NULL, 54 | NULL, 55 | NULL); 56 | -------------------------------------------------------------------------------- /c_src/extensor.hpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * 3 | * MODULE: extensor.hpp 4 | * PURPOSE: extensor nif helpers 5 | * 6 | ***************************************************************************/ 7 | #ifndef __EXTENSOR_HPP 8 | #define __EXTENSOR_HPP 9 | /*-------------------[ Pre Include Defines ]-------------------*/ 10 | /*-------------------[ Library Include Files ]-------------------*/ 11 | #include 12 | #include 13 | #include 14 | /*-------------------[ Project Include Files ]-------------------*/ 15 | /*-------------------[ Macros/Constants/Types ]-------------------*/ 16 | #define CHECK(result, ...) \ 17 | ({ \ 18 | auto r = (result); \ 19 | if (!r) \ 20 | throw NifError(__VA_ARGS__); \ 21 | r; \ 22 | }) 23 | #define CHECKALLOC(result) \ 24 | CHECK(result, "alloc_failed"); 25 | /*-------------------[ Classes ]-------------------*/ 26 | /*-----------< CLASS: NifError >--------------------------------------------- 27 | // Purpose: simple nif exception class 28 | ---------------------------------------------------------------------------*/ 29 | class NifError { 30 | public: 31 | NifError (const char* code = "unknown", const char* reason = "") { 32 | strncpy(_code, code, sizeof(_code) - 1); 33 | _code[sizeof(_code) - 1] = 0; 34 | strncpy(_reason, reason, sizeof(_reason) - 1); 35 | _reason[sizeof(_reason) - 1] = 0; 36 | } 37 | const char* code () const { 38 | return _code; 39 | } 40 | const char* reason () const { 41 | return _reason; 42 | } 43 | ERL_NIF_TERM to_term (ErlNifEnv* env) const { 44 | return enif_raise_exception( 45 | env, 46 | enif_make_tuple2( 47 | env, 48 | enif_make_atom(env, code()), 49 | strlen(reason()) 50 | ? enif_make_string(env, reason(), ERL_NIF_LATIN1) 51 | : enif_make_atom(env, "nil"))); 52 | } 53 | private: 54 | char _code[128 + 1]; 55 | char _reason[256 + 1]; 56 | }; 57 | /*-------------------[ Global Variables ]-------------------*/ 58 | /*-------------------[ Global Prototypes ]-------------------*/ 59 | template inline T* nif_alloc (int count = 1) { 60 | T* t = (T*)calloc(count, sizeof(T)); 61 | CHECKALLOC(t); 62 | return t; 63 | } 64 | template inline T* nif_clone (const T* source, int count = 1) { 65 | T* t = nif_alloc(count); 66 | memcpy(t, source, count * sizeof(T)); 67 | return t; 68 | } 69 | inline void nif_free (void* t) { 70 | if (t) 71 | free(t); 72 | } 73 | #endif // __EXTENSOR_HPP 74 | -------------------------------------------------------------------------------- /coveralls.json: -------------------------------------------------------------------------------- 1 | { 2 | "skip_files": [ 3 | "lib/tensorflow", 4 | "lib/extensor/nif.ex" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /docker/ubuntu-cpu.dockerfile: -------------------------------------------------------------------------------- 1 | FROM nvidia/cuda:10.1-cudnn7-runtime-ubuntu16.04 2 | 3 | # install packages 4 | RUN apt-get update -qq && apt-get install -y \ 5 | build-essential curl locales libatlas-base-dev 6 | 7 | # install tensorflow 8 | RUN curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.3.1.tar.gz | \ 9 | tar -C /usr/local -xz 10 | 11 | # install elixir 12 | ENV LANG=en_US.UTF-8 \ 13 | LANGUAGE=en_US:en \ 14 | LC_ALL=en_US.UTF-8 15 | RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ 16 | locale-gen 17 | RUN curl https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb > /tmp/erlang-solutions_1.0_all.deb && \ 18 | dpkg -i /tmp/erlang-solutions_1.0_all.deb && \ 19 | apt-get update -qq && apt-get install -y esl-erlang=1:23.1-1 elixir=1.10.4-1 && \ 20 | mix local.rebar --force && \ 21 | mix local.hex --force 22 | 23 | ADD mix.exs . 24 | ADD c_src ./c_src 25 | ADD lib ./lib 26 | ADD test ./test 27 | RUN mkdir priv 28 | RUN mix deps.get 29 | RUN mix compile 30 | 31 | CMD ["iex", "-S", "mix"] 32 | -------------------------------------------------------------------------------- /docker/ubuntu-gpu.dockerfile: -------------------------------------------------------------------------------- 1 | FROM nvidia/cuda:10.1-cudnn7-runtime-ubuntu16.04 2 | 3 | # install packages 4 | RUN apt-get update -qq && apt-get install -y \ 5 | build-essential curl locales libatlas-base-dev 6 | 7 | # install tensorflow 8 | RUN curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.3.1.tar.gz | \ 9 | tar -C /usr/local -xz 10 | 11 | # install elixir 12 | ENV LANG=en_US.UTF-8 \ 13 | LANGUAGE=en_US:en \ 14 | LC_ALL=en_US.UTF-8 15 | RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \ 16 | locale-gen 17 | RUN curl https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb > /tmp/erlang-solutions_1.0_all.deb && \ 18 | dpkg -i /tmp/erlang-solutions_1.0_all.deb && \ 19 | apt-get update -qq && apt-get install -y esl-erlang=1:23.1-1 elixir=1.10.4-1 && \ 20 | mix local.rebar --force && \ 21 | mix local.hex --force 22 | 23 | ADD mix.exs . 24 | ADD c_src ./c_src 25 | ADD lib ./lib 26 | ADD test ./test 27 | RUN mkdir priv 28 | RUN mix deps.get 29 | RUN mix compile 30 | 31 | CMD ["iex", "-S", "mix"] 32 | -------------------------------------------------------------------------------- /lib/extensor/matrex.ex: -------------------------------------------------------------------------------- 1 | if Code.ensure_loaded?(Matrex) do 2 | defmodule Extensor.Matrex do 3 | @moduledoc """ 4 | Optional `Matrex` integration 5 | """ 6 | 7 | alias Extensor.Tensor 8 | 9 | @doc """ 10 | Convert a `Matrex` matrix to a tensor struct 11 | """ 12 | @spec to_tensor(matrix :: Matrex.t()) :: Tensor.t() 13 | def to_tensor(%Matrex{ 14 | data: 15 | <> 17 | }) do 18 | %Tensor{ 19 | type: :float, 20 | shape: {rows, cols}, 21 | data: body 22 | } 23 | end 24 | 25 | @doc """ 26 | Convert from an `Tensor` struct to a `Matrex` matrix 27 | 28 | Currently, this only works for two dimensional tensors and the type _must be_ 29 | `:float`. 30 | """ 31 | @spec from_tensor(tensor :: Tensor.t()) :: Matrex.t() 32 | def from_tensor(tensor) do 33 | cond do 34 | tensor.type != :float -> 35 | raise ArgumentError, "invalid tensor type: #{tensor.type}" 36 | 37 | tuple_size(tensor.shape) != 2 -> 38 | raise ArgumentError, 39 | "invalid tensor shape: #{tuple_size(tensor.shape)}" 40 | 41 | true -> 42 | {r, c} = tensor.shape 43 | 44 | %Matrex{ 45 | data: 46 | <> <> 47 | <> <> tensor.data 48 | } 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/extensor/nif.ex: -------------------------------------------------------------------------------- 1 | defmodule Extensor.NIF do 2 | @moduledoc """ 3 | NIF wrapper module for tensorflow adapter functions 4 | """ 5 | 6 | @type tensor_map :: %{String.t() => {integer(), tuple(), binary()}} 7 | 8 | @on_load :init 9 | 10 | @doc "module initialization callback" 11 | @spec init() :: :ok 12 | def init do 13 | path = Path.join(Application.app_dir(:extensor, "priv"), "extensor") 14 | 15 | with {:error, reason} <- :erlang.load_nif(String.to_charlist(path), 0) do 16 | raise inspect(reason) 17 | end 18 | end 19 | 20 | @doc "loads a custom op kernel library" 21 | @spec tf_load_library(name :: String.t()) :: :ok 22 | def tf_load_library(_name) do 23 | :erlang.nif_error(:nif_library_not_loaded) 24 | end 25 | 26 | @doc "loads a graph_def protobuf into a new tensorflow session" 27 | @spec tf_parse_frozen_graph(graph_pb :: binary(), config_pb :: binary()) :: 28 | reference() 29 | def tf_parse_frozen_graph(_graph_pb, _config_pb) do 30 | :erlang.nif_error(:nif_library_not_loaded) 31 | end 32 | 33 | @doc "loads a saved_model from a path into a new tensorflow session" 34 | @spec tf_load_saved_model( 35 | path :: String.t(), 36 | tag :: String.t(), 37 | config_pb :: binary() 38 | ) :: {reference(), binary()} 39 | def tf_load_saved_model(_path, _tag, _config_pb) do 40 | :erlang.nif_error(:nif_library_not_loaded) 41 | end 42 | 43 | @doc "executes the graph in a running session" 44 | @spec tf_run_session( 45 | session :: reference(), 46 | input_tensors :: tensor_map(), 47 | output_names :: [String.t()] 48 | ) :: tensor_map() 49 | def tf_run_session(_session, _input_tensors, _output_names) do 50 | :erlang.nif_error(:nif_library_not_loaded) 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/extensor/session.ex: -------------------------------------------------------------------------------- 1 | defmodule Extensor.Session do 2 | @moduledoc """ 3 | The session module provides functions for loading tensorflow graphs into 4 | a session and executing operations within the session. Graphs are 5 | represented by protocol buffers and named tensors are used for all 6 | inputs/outputs. 7 | 8 | There are two primary methods for serializing models in tensorflow: 9 | frozen graph_defs and saved_models. A frozen graph_def is just a protocol 10 | buffer containing a compute graph with no variables (all variables have 11 | been frozen as consts). A saved_model is a directory containing metadata 12 | used for tensorflow serving (TFS) as well as weights for graph variables. 13 | For more information on these formats, see: 14 | 15 | * [graph_def](https://www.tensorflow.org/extend/tool_developers/#graphdef) 16 | * [saved_model](https://www.tensorflow.org/programmers_guide/saved_model) 17 | 18 | This module can be used to load either type of model. 19 | `parse/load_frozen_graph` loads a graph_def protocol buffer and imports 20 | it using `TF_GraphImportGraphDef`, and `load_saved_model` loads a 21 | saved_model using `TF_LoadSessionFromSavedModel`. Both functions create and 22 | return a reference to a tensorflow session that can be used to run 23 | operations, like model inference. A tensorflow ConfigProto can be passed to 24 | either function, in order to configure the session (GPU options, etc.). 25 | 26 | Once the session has been created, it can be executed any number of times 27 | using the `run` function. Tensorflow sessions are also thread-safe and 28 | maintain graph state per call, so they can be executed in parallel. The 29 | run function accepts a map of named input tensors and a list of output 30 | tensor names to evaluate. 31 | 32 | ### Example (Pythagorean Triple): 33 | ```elixir 34 | iex> session = Extensor.Session.load_saved_model!("test/data/pythagoras") 35 | 36 | iex> input = %{ 37 | "a" => Extensor.Tensor.from_list([5]), 38 | "b" => Extensor.Tensor.from_list([12]) 39 | } 40 | 41 | iex> output = Extensor.Session.run!(session, input, ["c"]) 42 | 43 | iex> Extensor.Tensor.to_list(output["c"]) 44 | [13.0] 45 | ``` 46 | 47 | See the `Tensorflow.ConfigProto` module and 48 | [documentation]( 49 | https://www.tensorflow.org/versions/r1.0/api_docs/python/tf/ConfigProto) 50 | for more information on how to pass configuration when creating a new 51 | session. The tensorflow protocol buffer modules were generated with the 52 | [protobuf-elixir](https://github.com/tony612/protobuf-elixir) library. 53 | """ 54 | 55 | alias Extensor.{NIF, Tensor} 56 | alias Tensorflow.{ConfigProto, MetaGraphDef, SignatureDef} 57 | 58 | @type t :: %__MODULE__{ 59 | resource: reference(), 60 | signatures: %{String.t() => SignatureDef.t()} 61 | } 62 | 63 | @default_config ConfigProto.new() 64 | 65 | @atom2tft %{ 66 | float: 1, 67 | double: 2, 68 | int32: 3, 69 | uint8: 4, 70 | int16: 5, 71 | int8: 6, 72 | string: 7, 73 | complex64: 8, 74 | complex: 8, 75 | int64: 9, 76 | bool: 10, 77 | qint8: 11, 78 | quint8: 12, 79 | qint32: 13, 80 | bfloat16: 14, 81 | qint16: 15, 82 | quint16: 16, 83 | uint16: 17, 84 | complex128: 18, 85 | half: 19, 86 | resource: 20, 87 | variant: 21, 88 | uint32: 22, 89 | uint64: 23 90 | } 91 | 92 | @tft2atom Map.new(@atom2tft, fn {k, v} -> {v, k} end) 93 | @signature_default %SignatureDef{inputs: %{}, outputs: %{}} 94 | 95 | defstruct [:resource, signatures: %{}] 96 | 97 | @doc "loads a custom op kernel library" 98 | @spec load_library(name :: String.t()) :: :ok | {:error, any()} 99 | def load_library(name) do 100 | load_library!(name) 101 | :ok 102 | rescue 103 | e -> {:error, e} 104 | end 105 | 106 | @doc "loads a custom op kernel library" 107 | @spec load_library!(name :: String.t()) :: :ok 108 | def load_library!(name) do 109 | NIF.tf_load_library(name) 110 | end 111 | 112 | @doc "loads a graph_def from a file path" 113 | @spec load_frozen_graph( 114 | path :: String.t(), 115 | config :: %ConfigProto{} 116 | ) :: {:ok, t()} | {:error, any()} 117 | def load_frozen_graph(path, config \\ @default_config) do 118 | {:ok, load_frozen_graph!(path, config)} 119 | rescue 120 | e -> {:error, e} 121 | end 122 | 123 | @doc "loads a graph_def from a file path" 124 | @spec load_frozen_graph!( 125 | path :: String.t(), 126 | config :: %ConfigProto{} 127 | ) :: t() | no_return() 128 | def load_frozen_graph!(path, config \\ @default_config) do 129 | path 130 | |> File.read!() 131 | |> parse_frozen_graph!(config) 132 | end 133 | 134 | @doc "loads a graph_def from a binary string" 135 | @spec parse_frozen_graph( 136 | graph_pb :: binary(), 137 | config :: %ConfigProto{} 138 | ) :: {:ok, t()} | {:error, any()} 139 | def parse_frozen_graph(graph_pb, config \\ @default_config) do 140 | {:ok, parse_frozen_graph!(graph_pb, config)} 141 | rescue 142 | e -> {:error, e} 143 | end 144 | 145 | @doc "loads a graph_def from a binary string" 146 | @spec parse_frozen_graph!( 147 | graph_pb :: binary(), 148 | config :: %ConfigProto{} 149 | ) :: t() | no_return() 150 | def parse_frozen_graph!(graph_pb, config \\ @default_config) do 151 | resource = NIF.tf_parse_frozen_graph(graph_pb, ConfigProto.encode(config)) 152 | 153 | %__MODULE__{ 154 | resource: resource 155 | } 156 | end 157 | 158 | @doc "loads a saved_model from a directory path" 159 | @spec load_saved_model( 160 | path :: String.t(), 161 | config :: %ConfigProto{}, 162 | tag :: String.t() 163 | ) :: {:ok, t()} | {:error, any()} 164 | def load_saved_model(path, config \\ @default_config, tag \\ "serve") do 165 | {:ok, load_saved_model!(path, config, tag)} 166 | rescue 167 | e -> {:error, e} 168 | end 169 | 170 | @doc "loads a saved_model from a directory path" 171 | @spec load_saved_model!( 172 | path :: String.t(), 173 | config :: %ConfigProto{}, 174 | tag :: String.t() 175 | ) :: t() | no_return() 176 | def load_saved_model!(path, config \\ @default_config, tag \\ "serve") do 177 | # load the saved model directory from the nif 178 | {resource, metagraph} = 179 | NIF.tf_load_saved_model(path, tag, ConfigProto.encode(config)) 180 | 181 | # parse the metagraph for signatures 182 | metagraph = MetaGraphDef.decode(metagraph) 183 | 184 | # return the session 185 | %__MODULE__{ 186 | resource: resource, 187 | signatures: metagraph.signature_def 188 | } 189 | end 190 | 191 | @doc "executes a tensorflow session" 192 | @spec run( 193 | session :: t(), 194 | input_tensors :: %{String.t() => Tensor.t()}, 195 | output_names :: [String.t(), ...] | nil, 196 | signature :: String.t() 197 | ) :: {:ok, %{String.t() => Tensor.t()}} | {:error, any} 198 | def run( 199 | session, 200 | input_tensors, 201 | output_names \\ nil, 202 | signature \\ "serving_default" 203 | ) do 204 | {:ok, run!(session, input_tensors, output_names, signature)} 205 | rescue 206 | e -> {:error, e} 207 | end 208 | 209 | @doc "executes a tensorflow session" 210 | @spec run!( 211 | session :: t(), 212 | input_tensors :: %{String.t() => Tensor.t()}, 213 | output_names :: [String.t(), ...] | nil, 214 | signature :: String.t() 215 | ) :: %{String.t() => Tensor.t()} 216 | def run!( 217 | session, 218 | input_tensors, 219 | output_names \\ nil, 220 | signature \\ "serving_default" 221 | ) do 222 | # fetch the metadata for the requested signature and 223 | # default the output tensors to the signature outputs 224 | signature = session.signatures[signature] || @signature_default 225 | output_names = output_names || Map.keys(signature.outputs) 226 | 227 | # map the input names through the signaturedef mapping 228 | # convert the input tensor structs to values accepted by the nif 229 | input_tensors = 230 | input_tensors 231 | |> Map.new(fn {k, v} -> {sig2tensor(k, signature.inputs), ex2tf(v)} end) 232 | 233 | # create a parallel list of mapped tensor names, 234 | # so that we can invert the mapping on the other side 235 | result_names = 236 | output_names 237 | |> Enum.map(&sig2tensor(&1, signature.outputs)) 238 | 239 | # run tensorflow inference 240 | output_tensors = 241 | NIF.tf_run_session( 242 | session.resource, 243 | input_tensors, 244 | result_names 245 | ) 246 | 247 | # map the output tensor names through the signaturedef mapping 248 | # convert the nif tensor values to elixir tensor structs 249 | Enum.zip(output_names, result_names) 250 | |> Map.new(fn {s, t} -> {s, tf2ex(output_tensors[t])} end) 251 | end 252 | 253 | # convert a metagraph signature name to a tensor name 254 | defp sig2tensor(key, map) do 255 | case map[key] do 256 | %{encoding: {:name, key}} -> key 257 | _ -> key 258 | end 259 | end 260 | 261 | # convert an elixir tensor to a tensorflow tensor tuple 262 | defp ex2tf(tensor) do 263 | Tensor.validate!(tensor) 264 | {Map.fetch!(@atom2tft, tensor.type), tensor.shape, tensor.data} 265 | end 266 | 267 | # convert a tensorflow tensor tuple to an elixir tensor 268 | defp tf2ex({type, shape, data}) do 269 | %Tensor{type: Map.fetch!(@tft2atom, type), shape: shape, data: data} 270 | end 271 | end 272 | -------------------------------------------------------------------------------- /lib/extensor/tensor.ex: -------------------------------------------------------------------------------- 1 | defmodule Extensor.Tensor do 2 | @moduledoc """ 3 | This is a simple wrapper struct for a tensorflow tensor. It holds the 4 | data type, shape (dimensions), and binary data buffer for a tensor. 5 | 6 | The layout of the buffer is the same as what is used in tensorflow - 7 | row-major dimension ordering with native endian byte order. Extensor 8 | performs very little manipulation of the data buffer, in order to minimize 9 | the performance impact of using tensorflow from Elixir. 10 | 11 | The following atoms are used to represent the corresponding tensorflow 12 | data types. 13 | 14 | |atom|tensorflow type| 15 | |-|-| 16 | |`:float`|`TF_FLOAT`| 17 | |`:double`|`TF_DOUBLE`| 18 | |`:int32`|`TF_INT32`| 19 | |`:uint8`|`TF_UINT8`| 20 | |`:int16`|`TF_INT16`| 21 | |`:int8`|`TF_INT8`| 22 | |`:string`|`TF_STRING`| 23 | |`:complex64`|`TF_COMPLEX64`| 24 | |`:complex`|`TF_COMPLEX`| 25 | |`:int64`|`TF_INT64`| 26 | |`:bool`|`TF_BOOL`| 27 | |`:qint8`|`TF_QINT8`| 28 | |`:quint8`|`TF_QUINT8`| 29 | |`:qint32`|`TF_QINT32`| 30 | |`:bfloat16`|`TF_BFLOAT16`| 31 | |`:qint16`|`TF_QINT16`| 32 | |`:quint16`|`TF_QUINT16`| 33 | |`:uint16`|`TF_UINT16`| 34 | |`:complex128`|`TF_COMPLEX128`| 35 | |`:half`|`TF_HALF`| 36 | |`:resource`|`TF_RESOURCE`| 37 | |`:variant`|`TF_VARIANT`| 38 | |`:uint32`|`TF_UINT32`| 39 | |`:uint64`|`TF_UINT64`| 40 | 41 | For convenience, though, functions are provided for constructing tensors 42 | from (nested) lists. These functions use binary pattern matching and 43 | concatenation to convert Elixir data types to/from the tensorflow binary 44 | standard. 45 | 46 | Example: 47 | ```elixir 48 | iex> tensor = Extensor.Tensor.from_list([[1, 2], [3, 4]], :double) 49 | %Extensor.Tensor{ 50 | type: :double, 51 | shape: {2, 2}, 52 | data: <<0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64>> 53 | } 54 | 55 | iex> Extensor.Tensor.to_list(tensor) 56 | [[1.0, 2.0], [3.0, 4.0]] 57 | ``` 58 | 59 | This module can also be used to verify that a tensor's shape is consistent 60 | with its binary size. This can avoid segfaults in tensorflow when 61 | shape/size don't match. 62 | """ 63 | 64 | @type data_type :: 65 | :float 66 | | :double 67 | | :int32 68 | | :uint8 69 | | :int16 70 | | :int8 71 | | :string 72 | | :complex64 73 | | :complex 74 | | :int64 75 | | :bool 76 | | :qint8 77 | | :quint8 78 | | :qint32 79 | | :bfloat16 80 | | :qint16 81 | | :quint16 82 | | :uint16 83 | | :complex128 84 | | :half 85 | | :resource 86 | | :variant 87 | | :uint32 88 | | :uint64 89 | 90 | @type t :: %__MODULE__{ 91 | type: data_type(), 92 | shape: tuple(), 93 | data: binary() 94 | } 95 | 96 | defstruct type: :float, shape: {0}, data: <<>> 97 | 98 | @type_byte_size %{ 99 | float: 4, 100 | double: 8, 101 | int32: 4, 102 | uint8: 1, 103 | int16: 2, 104 | int8: 1, 105 | string: nil, 106 | complex64: 16, 107 | complex: 8, 108 | int64: 8, 109 | bool: 1, 110 | qint8: 1, 111 | quint8: 1, 112 | qint32: 4, 113 | bfloat16: 2, 114 | qint16: 2, 115 | quint16: 2, 116 | uint16: 2, 117 | complex128: 32, 118 | half: 2, 119 | resource: nil, 120 | variant: nil, 121 | uint32: 4, 122 | uint64: 8 123 | } 124 | 125 | @doc "converts a (nested) list to a tensor structure" 126 | @spec from_list(list :: list(), type :: data_type()) :: t() 127 | def from_list(list, type \\ :float) do 128 | shape = List.to_tuple(list_shape(list)) 129 | 130 | data = 131 | list 132 | |> List.flatten() 133 | |> Enum.map(&to_binary(&1, type)) 134 | |> IO.iodata_to_binary() 135 | 136 | %__MODULE__{type: type, shape: shape, data: data} 137 | end 138 | 139 | defp list_shape([head | _] = list), do: [length(list) | list_shape(head)] 140 | defp list_shape([]), do: [0] 141 | defp list_shape(_), do: [] 142 | 143 | @doc "converts a tensor to a nested list" 144 | @spec to_list(tensor :: t()) :: list() 145 | def to_list(%__MODULE__{data: <<>>} = _tensor) do 146 | [] 147 | end 148 | 149 | def to_list(tensor) do 150 | to_list( 151 | tensor.data, 152 | tensor.type, 153 | _offset = 0, 154 | _size = byte_size(tensor.data), 155 | Tuple.to_list(tensor.shape) 156 | ) 157 | end 158 | 159 | defp to_list(data, type, offset, size, [dim | shape]) do 160 | dim_size = div(size, dim) 161 | 162 | Enum.map(0..(dim - 1), fn i -> 163 | to_list(data, type, offset + i * dim_size, dim_size, shape) 164 | end) 165 | end 166 | 167 | defp to_list(data, type, offset, size, []) do 168 | from_binary(binary_part(data, offset, size), type) 169 | end 170 | 171 | defp from_binary(<>, :float), do: v 172 | defp from_binary(<>, :double), do: v 173 | defp from_binary(<>, :int32), do: v 174 | defp from_binary(<>, :uint8), do: v 175 | defp from_binary(<>, :int16), do: v 176 | defp from_binary(<>, :int8), do: v 177 | defp from_binary(<>, :int64), do: v 178 | defp from_binary(<>, :bool), do: v 179 | defp from_binary(<>, :qint8), do: v 180 | defp from_binary(<>, :quint8), do: v 181 | defp from_binary(<>, :qint32), do: v 182 | defp from_binary(<>, :qint16), do: v 183 | defp from_binary(<>, :quint16), do: v 184 | defp from_binary(<>, :uint32), do: v 185 | defp from_binary(<>, :uint64), do: v 186 | 187 | defp to_binary(v, :float), do: <> 188 | defp to_binary(v, :double), do: <> 189 | defp to_binary(v, :int32), do: <> 190 | defp to_binary(v, :uint8), do: <> 191 | defp to_binary(v, :int16), do: <> 192 | defp to_binary(v, :int8), do: <> 193 | defp to_binary(v, :int64), do: <> 194 | defp to_binary(v, :bool), do: <> 195 | defp to_binary(v, :qint8), do: <> 196 | defp to_binary(v, :quint8), do: <> 197 | defp to_binary(v, :qint32), do: <> 198 | defp to_binary(v, :qint16), do: <> 199 | defp to_binary(v, :quint16), do: <> 200 | defp to_binary(v, :uint32), do: <> 201 | defp to_binary(v, :uint64), do: <> 202 | 203 | @doc "validates the tensor shape/size" 204 | @spec validate(tensor :: t()) :: :ok | {:error, any()} 205 | def validate(tensor) do 206 | validate!(tensor) 207 | rescue 208 | e -> {:error, e} 209 | end 210 | 211 | @doc "validates the tensor shape/size" 212 | @spec validate!(tensor :: t()) :: :ok | no_return() 213 | def validate!(tensor) do 214 | if !Map.has_key?(@type_byte_size, tensor.type) do 215 | raise ArgumentError, "invalid tensor type: #{tensor.type}" 216 | end 217 | 218 | if type_size = Map.fetch!(@type_byte_size, tensor.type) do 219 | expect = 220 | tensor.shape 221 | |> Tuple.to_list() 222 | |> Enum.reduce(type_size, &(&1 * &2)) 223 | 224 | actual = byte_size(tensor.data) 225 | 226 | if expect !== actual do 227 | raise ArgumentError, "tensor size mismatch: #{actual} != #{expect}" 228 | end 229 | end 230 | 231 | :ok 232 | end 233 | end 234 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/allocation_description.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.AllocationDescription do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | requested_bytes: integer, 7 | allocated_bytes: integer, 8 | allocator_name: String.t(), 9 | allocation_id: integer, 10 | has_single_reference: boolean, 11 | ptr: non_neg_integer 12 | } 13 | defstruct [ 14 | :requested_bytes, 15 | :allocated_bytes, 16 | :allocator_name, 17 | :allocation_id, 18 | :has_single_reference, 19 | :ptr 20 | ] 21 | 22 | field(:requested_bytes, 1, type: :int64) 23 | field(:allocated_bytes, 2, type: :int64) 24 | field(:allocator_name, 3, type: :string) 25 | field(:allocation_id, 4, type: :int64) 26 | field(:has_single_reference, 5, type: :bool) 27 | field(:ptr, 6, type: :uint64) 28 | end 29 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/api_def.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.ApiDef.Visibility do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: integer | :DEFAULT_VISIBILITY | :VISIBLE | :SKIP | :HIDDEN 6 | 7 | field(:DEFAULT_VISIBILITY, 0) 8 | field(:VISIBLE, 1) 9 | field(:SKIP, 2) 10 | field(:HIDDEN, 3) 11 | end 12 | 13 | defmodule Tensorflow.ApiDef.Endpoint do 14 | @moduledoc false 15 | use Protobuf, syntax: :proto3 16 | 17 | @type t :: %__MODULE__{ 18 | name: String.t(), 19 | deprecated: boolean, 20 | deprecation_version: integer 21 | } 22 | defstruct [:name, :deprecated, :deprecation_version] 23 | 24 | field(:name, 1, type: :string) 25 | field(:deprecated, 3, type: :bool) 26 | field(:deprecation_version, 4, type: :int32) 27 | end 28 | 29 | defmodule Tensorflow.ApiDef.Arg do 30 | @moduledoc false 31 | use Protobuf, syntax: :proto3 32 | 33 | @type t :: %__MODULE__{ 34 | name: String.t(), 35 | rename_to: String.t(), 36 | description: String.t() 37 | } 38 | defstruct [:name, :rename_to, :description] 39 | 40 | field(:name, 1, type: :string) 41 | field(:rename_to, 2, type: :string) 42 | field(:description, 3, type: :string) 43 | end 44 | 45 | defmodule Tensorflow.ApiDef.Attr do 46 | @moduledoc false 47 | use Protobuf, syntax: :proto3 48 | 49 | @type t :: %__MODULE__{ 50 | name: String.t(), 51 | rename_to: String.t(), 52 | default_value: Tensorflow.AttrValue.t() | nil, 53 | description: String.t() 54 | } 55 | defstruct [:name, :rename_to, :default_value, :description] 56 | 57 | field(:name, 1, type: :string) 58 | field(:rename_to, 2, type: :string) 59 | field(:default_value, 3, type: Tensorflow.AttrValue) 60 | field(:description, 4, type: :string) 61 | end 62 | 63 | defmodule Tensorflow.ApiDef do 64 | @moduledoc false 65 | use Protobuf, syntax: :proto3 66 | 67 | @type t :: %__MODULE__{ 68 | graph_op_name: String.t(), 69 | deprecation_message: String.t(), 70 | deprecation_version: integer, 71 | visibility: Tensorflow.ApiDef.Visibility.t(), 72 | endpoint: [Tensorflow.ApiDef.Endpoint.t()], 73 | in_arg: [Tensorflow.ApiDef.Arg.t()], 74 | out_arg: [Tensorflow.ApiDef.Arg.t()], 75 | arg_order: [String.t()], 76 | attr: [Tensorflow.ApiDef.Attr.t()], 77 | summary: String.t(), 78 | description: String.t(), 79 | description_prefix: String.t(), 80 | description_suffix: String.t() 81 | } 82 | defstruct [ 83 | :graph_op_name, 84 | :deprecation_message, 85 | :deprecation_version, 86 | :visibility, 87 | :endpoint, 88 | :in_arg, 89 | :out_arg, 90 | :arg_order, 91 | :attr, 92 | :summary, 93 | :description, 94 | :description_prefix, 95 | :description_suffix 96 | ] 97 | 98 | field(:graph_op_name, 1, type: :string) 99 | field(:deprecation_message, 12, type: :string) 100 | field(:deprecation_version, 13, type: :int32) 101 | field(:visibility, 2, type: Tensorflow.ApiDef.Visibility, enum: true) 102 | field(:endpoint, 3, repeated: true, type: Tensorflow.ApiDef.Endpoint) 103 | field(:in_arg, 4, repeated: true, type: Tensorflow.ApiDef.Arg) 104 | field(:out_arg, 5, repeated: true, type: Tensorflow.ApiDef.Arg) 105 | field(:arg_order, 11, repeated: true, type: :string) 106 | field(:attr, 6, repeated: true, type: Tensorflow.ApiDef.Attr) 107 | field(:summary, 7, type: :string) 108 | field(:description, 8, type: :string) 109 | field(:description_prefix, 9, type: :string) 110 | field(:description_suffix, 10, type: :string) 111 | end 112 | 113 | defmodule Tensorflow.ApiDefs do 114 | @moduledoc false 115 | use Protobuf, syntax: :proto3 116 | 117 | @type t :: %__MODULE__{ 118 | op: [Tensorflow.ApiDef.t()] 119 | } 120 | defstruct [:op] 121 | 122 | field(:op, 1, repeated: true, type: Tensorflow.ApiDef) 123 | end 124 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/attr_value.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.AttrValue.ListValue do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | s: [binary], 7 | i: [integer], 8 | f: [float | :infinity | :negative_infinity | :nan], 9 | b: [boolean], 10 | type: [[Tensorflow.DataType.t()]], 11 | shape: [Tensorflow.TensorShapeProto.t()], 12 | tensor: [Tensorflow.TensorProto.t()], 13 | func: [Tensorflow.NameAttrList.t()] 14 | } 15 | defstruct [:s, :i, :f, :b, :type, :shape, :tensor, :func] 16 | 17 | field(:s, 2, repeated: true, type: :bytes) 18 | field(:i, 3, repeated: true, type: :int64, packed: true) 19 | field(:f, 4, repeated: true, type: :float, packed: true) 20 | field(:b, 5, repeated: true, type: :bool, packed: true) 21 | 22 | field(:type, 6, 23 | repeated: true, 24 | type: Tensorflow.DataType, 25 | enum: true, 26 | packed: true 27 | ) 28 | 29 | field(:shape, 7, repeated: true, type: Tensorflow.TensorShapeProto) 30 | field(:tensor, 8, repeated: true, type: Tensorflow.TensorProto) 31 | field(:func, 9, repeated: true, type: Tensorflow.NameAttrList) 32 | end 33 | 34 | defmodule Tensorflow.AttrValue do 35 | @moduledoc false 36 | use Protobuf, syntax: :proto3 37 | 38 | @type t :: %__MODULE__{ 39 | value: {atom, any} 40 | } 41 | defstruct [:value] 42 | 43 | oneof(:value, 0) 44 | field(:s, 2, type: :bytes, oneof: 0) 45 | field(:i, 3, type: :int64, oneof: 0) 46 | field(:f, 4, type: :float, oneof: 0) 47 | field(:b, 5, type: :bool, oneof: 0) 48 | field(:type, 6, type: Tensorflow.DataType, enum: true, oneof: 0) 49 | field(:shape, 7, type: Tensorflow.TensorShapeProto, oneof: 0) 50 | field(:tensor, 8, type: Tensorflow.TensorProto, oneof: 0) 51 | field(:list, 1, type: Tensorflow.AttrValue.ListValue, oneof: 0) 52 | field(:func, 10, type: Tensorflow.NameAttrList, oneof: 0) 53 | field(:placeholder, 9, type: :string, oneof: 0) 54 | end 55 | 56 | defmodule Tensorflow.NameAttrList.AttrEntry do 57 | @moduledoc false 58 | use Protobuf, map: true, syntax: :proto3 59 | 60 | @type t :: %__MODULE__{ 61 | key: String.t(), 62 | value: Tensorflow.AttrValue.t() | nil 63 | } 64 | defstruct [:key, :value] 65 | 66 | field(:key, 1, type: :string) 67 | field(:value, 2, type: Tensorflow.AttrValue) 68 | end 69 | 70 | defmodule Tensorflow.NameAttrList do 71 | @moduledoc false 72 | use Protobuf, syntax: :proto3 73 | 74 | @type t :: %__MODULE__{ 75 | name: String.t(), 76 | attr: %{String.t() => Tensorflow.AttrValue.t() | nil} 77 | } 78 | defstruct [:name, :attr] 79 | 80 | field(:name, 1, type: :string) 81 | 82 | field(:attr, 2, 83 | repeated: true, 84 | type: Tensorflow.NameAttrList.AttrEntry, 85 | map: true 86 | ) 87 | end 88 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/cost_graph.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.CostGraphDef.Node.InputInfo do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | preceding_node: integer, 7 | preceding_port: integer 8 | } 9 | defstruct [:preceding_node, :preceding_port] 10 | 11 | field(:preceding_node, 1, type: :int32) 12 | field(:preceding_port, 2, type: :int32) 13 | end 14 | 15 | defmodule Tensorflow.CostGraphDef.Node.OutputInfo do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | size: integer, 21 | alias_input_port: integer, 22 | shape: Tensorflow.TensorShapeProto.t() | nil, 23 | dtype: Tensorflow.DataType.t() 24 | } 25 | defstruct [:size, :alias_input_port, :shape, :dtype] 26 | 27 | field(:size, 1, type: :int64) 28 | field(:alias_input_port, 2, type: :int64) 29 | field(:shape, 3, type: Tensorflow.TensorShapeProto) 30 | field(:dtype, 4, type: Tensorflow.DataType, enum: true) 31 | end 32 | 33 | defmodule Tensorflow.CostGraphDef.Node do 34 | @moduledoc false 35 | use Protobuf, syntax: :proto3 36 | 37 | @type t :: %__MODULE__{ 38 | name: String.t(), 39 | device: String.t(), 40 | id: integer, 41 | input_info: [Tensorflow.CostGraphDef.Node.InputInfo.t()], 42 | output_info: [Tensorflow.CostGraphDef.Node.OutputInfo.t()], 43 | temporary_memory_size: integer, 44 | persistent_memory_size: integer, 45 | host_temp_memory_size: integer, 46 | device_temp_memory_size: integer, 47 | device_persistent_memory_size: integer, 48 | compute_cost: integer, 49 | compute_time: integer, 50 | memory_time: integer, 51 | is_final: boolean, 52 | control_input: [integer], 53 | inaccurate: boolean 54 | } 55 | defstruct [ 56 | :name, 57 | :device, 58 | :id, 59 | :input_info, 60 | :output_info, 61 | :temporary_memory_size, 62 | :persistent_memory_size, 63 | :host_temp_memory_size, 64 | :device_temp_memory_size, 65 | :device_persistent_memory_size, 66 | :compute_cost, 67 | :compute_time, 68 | :memory_time, 69 | :is_final, 70 | :control_input, 71 | :inaccurate 72 | ] 73 | 74 | field(:name, 1, type: :string) 75 | field(:device, 2, type: :string) 76 | field(:id, 3, type: :int32) 77 | 78 | field(:input_info, 4, 79 | repeated: true, 80 | type: Tensorflow.CostGraphDef.Node.InputInfo 81 | ) 82 | 83 | field(:output_info, 5, 84 | repeated: true, 85 | type: Tensorflow.CostGraphDef.Node.OutputInfo 86 | ) 87 | 88 | field(:temporary_memory_size, 6, type: :int64) 89 | field(:persistent_memory_size, 12, type: :int64) 90 | field(:host_temp_memory_size, 10, type: :int64, deprecated: true) 91 | field(:device_temp_memory_size, 11, type: :int64, deprecated: true) 92 | field(:device_persistent_memory_size, 16, type: :int64, deprecated: true) 93 | field(:compute_cost, 9, type: :int64) 94 | field(:compute_time, 14, type: :int64) 95 | field(:memory_time, 15, type: :int64) 96 | field(:is_final, 7, type: :bool) 97 | field(:control_input, 8, repeated: true, type: :int32) 98 | field(:inaccurate, 17, type: :bool) 99 | end 100 | 101 | defmodule Tensorflow.CostGraphDef.AggregatedCost do 102 | @moduledoc false 103 | use Protobuf, syntax: :proto3 104 | 105 | @type t :: %__MODULE__{ 106 | cost: float | :infinity | :negative_infinity | :nan, 107 | dimension: String.t() 108 | } 109 | defstruct [:cost, :dimension] 110 | 111 | field(:cost, 1, type: :float) 112 | field(:dimension, 2, type: :string) 113 | end 114 | 115 | defmodule Tensorflow.CostGraphDef do 116 | @moduledoc false 117 | use Protobuf, syntax: :proto3 118 | 119 | @type t :: %__MODULE__{ 120 | node: [Tensorflow.CostGraphDef.Node.t()], 121 | cost: [Tensorflow.CostGraphDef.AggregatedCost.t()] 122 | } 123 | defstruct [:node, :cost] 124 | 125 | field(:node, 1, repeated: true, type: Tensorflow.CostGraphDef.Node) 126 | 127 | field(:cost, 2, repeated: true, type: Tensorflow.CostGraphDef.AggregatedCost) 128 | end 129 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/device_attributes.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.InterconnectLink do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | device_id: integer, 7 | type: String.t(), 8 | strength: integer 9 | } 10 | defstruct [:device_id, :type, :strength] 11 | 12 | field(:device_id, 1, type: :int32) 13 | field(:type, 2, type: :string) 14 | field(:strength, 3, type: :int32) 15 | end 16 | 17 | defmodule Tensorflow.LocalLinks do 18 | @moduledoc false 19 | use Protobuf, syntax: :proto3 20 | 21 | @type t :: %__MODULE__{ 22 | link: [Tensorflow.InterconnectLink.t()] 23 | } 24 | defstruct [:link] 25 | 26 | field(:link, 1, repeated: true, type: Tensorflow.InterconnectLink) 27 | end 28 | 29 | defmodule Tensorflow.DeviceLocality do 30 | @moduledoc false 31 | use Protobuf, syntax: :proto3 32 | 33 | @type t :: %__MODULE__{ 34 | bus_id: integer, 35 | numa_node: integer, 36 | links: Tensorflow.LocalLinks.t() | nil 37 | } 38 | defstruct [:bus_id, :numa_node, :links] 39 | 40 | field(:bus_id, 1, type: :int32) 41 | field(:numa_node, 2, type: :int32) 42 | field(:links, 3, type: Tensorflow.LocalLinks) 43 | end 44 | 45 | defmodule Tensorflow.DeviceAttributes do 46 | @moduledoc false 47 | use Protobuf, syntax: :proto3 48 | 49 | @type t :: %__MODULE__{ 50 | name: String.t(), 51 | device_type: String.t(), 52 | memory_limit: integer, 53 | locality: Tensorflow.DeviceLocality.t() | nil, 54 | incarnation: non_neg_integer, 55 | physical_device_desc: String.t() 56 | } 57 | defstruct [ 58 | :name, 59 | :device_type, 60 | :memory_limit, 61 | :locality, 62 | :incarnation, 63 | :physical_device_desc 64 | ] 65 | 66 | field(:name, 1, type: :string) 67 | field(:device_type, 2, type: :string) 68 | field(:memory_limit, 4, type: :int64) 69 | field(:locality, 5, type: Tensorflow.DeviceLocality) 70 | field(:incarnation, 6, type: :fixed64) 71 | field(:physical_device_desc, 7, type: :string) 72 | end 73 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/function.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.FunctionDefLibrary do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | function: [Tensorflow.FunctionDef.t()], 7 | gradient: [Tensorflow.GradientDef.t()] 8 | } 9 | defstruct [:function, :gradient] 10 | 11 | field(:function, 1, repeated: true, type: Tensorflow.FunctionDef) 12 | field(:gradient, 2, repeated: true, type: Tensorflow.GradientDef) 13 | end 14 | 15 | defmodule Tensorflow.FunctionDef.AttrEntry do 16 | @moduledoc false 17 | use Protobuf, map: true, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | key: String.t(), 21 | value: Tensorflow.AttrValue.t() | nil 22 | } 23 | defstruct [:key, :value] 24 | 25 | field(:key, 1, type: :string) 26 | field(:value, 2, type: Tensorflow.AttrValue) 27 | end 28 | 29 | defmodule Tensorflow.FunctionDef.ArgAttrs.AttrEntry do 30 | @moduledoc false 31 | use Protobuf, map: true, syntax: :proto3 32 | 33 | @type t :: %__MODULE__{ 34 | key: String.t(), 35 | value: Tensorflow.AttrValue.t() | nil 36 | } 37 | defstruct [:key, :value] 38 | 39 | field(:key, 1, type: :string) 40 | field(:value, 2, type: Tensorflow.AttrValue) 41 | end 42 | 43 | defmodule Tensorflow.FunctionDef.ArgAttrs do 44 | @moduledoc false 45 | use Protobuf, syntax: :proto3 46 | 47 | @type t :: %__MODULE__{ 48 | attr: %{String.t() => Tensorflow.AttrValue.t() | nil} 49 | } 50 | defstruct [:attr] 51 | 52 | field(:attr, 1, 53 | repeated: true, 54 | type: Tensorflow.FunctionDef.ArgAttrs.AttrEntry, 55 | map: true 56 | ) 57 | end 58 | 59 | defmodule Tensorflow.FunctionDef.ArgAttrEntry do 60 | @moduledoc false 61 | use Protobuf, map: true, syntax: :proto3 62 | 63 | @type t :: %__MODULE__{ 64 | key: non_neg_integer, 65 | value: Tensorflow.FunctionDef.ArgAttrs.t() | nil 66 | } 67 | defstruct [:key, :value] 68 | 69 | field(:key, 1, type: :uint32) 70 | field(:value, 2, type: Tensorflow.FunctionDef.ArgAttrs) 71 | end 72 | 73 | defmodule Tensorflow.FunctionDef.ResourceArgUniqueIdEntry do 74 | @moduledoc false 75 | use Protobuf, map: true, syntax: :proto3 76 | 77 | @type t :: %__MODULE__{ 78 | key: non_neg_integer, 79 | value: non_neg_integer 80 | } 81 | defstruct [:key, :value] 82 | 83 | field(:key, 1, type: :uint32) 84 | field(:value, 2, type: :uint32) 85 | end 86 | 87 | defmodule Tensorflow.FunctionDef.RetEntry do 88 | @moduledoc false 89 | use Protobuf, map: true, syntax: :proto3 90 | 91 | @type t :: %__MODULE__{ 92 | key: String.t(), 93 | value: String.t() 94 | } 95 | defstruct [:key, :value] 96 | 97 | field(:key, 1, type: :string) 98 | field(:value, 2, type: :string) 99 | end 100 | 101 | defmodule Tensorflow.FunctionDef.ControlRetEntry do 102 | @moduledoc false 103 | use Protobuf, map: true, syntax: :proto3 104 | 105 | @type t :: %__MODULE__{ 106 | key: String.t(), 107 | value: String.t() 108 | } 109 | defstruct [:key, :value] 110 | 111 | field(:key, 1, type: :string) 112 | field(:value, 2, type: :string) 113 | end 114 | 115 | defmodule Tensorflow.FunctionDef do 116 | @moduledoc false 117 | use Protobuf, syntax: :proto3 118 | 119 | @type t :: %__MODULE__{ 120 | signature: Tensorflow.OpDef.t() | nil, 121 | attr: %{String.t() => Tensorflow.AttrValue.t() | nil}, 122 | arg_attr: %{ 123 | non_neg_integer => Tensorflow.FunctionDef.ArgAttrs.t() | nil 124 | }, 125 | resource_arg_unique_id: %{non_neg_integer => non_neg_integer}, 126 | node_def: [Tensorflow.NodeDef.t()], 127 | ret: %{String.t() => String.t()}, 128 | control_ret: %{String.t() => String.t()} 129 | } 130 | defstruct [ 131 | :signature, 132 | :attr, 133 | :arg_attr, 134 | :resource_arg_unique_id, 135 | :node_def, 136 | :ret, 137 | :control_ret 138 | ] 139 | 140 | field(:signature, 1, type: Tensorflow.OpDef) 141 | 142 | field(:attr, 5, 143 | repeated: true, 144 | type: Tensorflow.FunctionDef.AttrEntry, 145 | map: true 146 | ) 147 | 148 | field(:arg_attr, 7, 149 | repeated: true, 150 | type: Tensorflow.FunctionDef.ArgAttrEntry, 151 | map: true 152 | ) 153 | 154 | field(:resource_arg_unique_id, 8, 155 | repeated: true, 156 | type: Tensorflow.FunctionDef.ResourceArgUniqueIdEntry, 157 | map: true 158 | ) 159 | 160 | field(:node_def, 3, repeated: true, type: Tensorflow.NodeDef) 161 | 162 | field(:ret, 4, 163 | repeated: true, 164 | type: Tensorflow.FunctionDef.RetEntry, 165 | map: true 166 | ) 167 | 168 | field(:control_ret, 6, 169 | repeated: true, 170 | type: Tensorflow.FunctionDef.ControlRetEntry, 171 | map: true 172 | ) 173 | end 174 | 175 | defmodule Tensorflow.GradientDef do 176 | @moduledoc false 177 | use Protobuf, syntax: :proto3 178 | 179 | @type t :: %__MODULE__{ 180 | function_name: String.t(), 181 | gradient_func: String.t() 182 | } 183 | defstruct [:function_name, :gradient_func] 184 | 185 | field(:function_name, 1, type: :string) 186 | field(:gradient_func, 2, type: :string) 187 | end 188 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/graph.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.GraphDef do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | node: [Tensorflow.NodeDef.t()], 7 | versions: Tensorflow.VersionDef.t() | nil, 8 | version: integer, 9 | library: Tensorflow.FunctionDefLibrary.t() | nil 10 | } 11 | defstruct [:node, :versions, :version, :library] 12 | 13 | field(:node, 1, repeated: true, type: Tensorflow.NodeDef) 14 | field(:versions, 4, type: Tensorflow.VersionDef) 15 | field(:version, 3, type: :int32, deprecated: true) 16 | field(:library, 2, type: Tensorflow.FunctionDefLibrary) 17 | end 18 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/graph_transfer_info.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.GraphTransferInfo.Destination do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: integer | :NOP | :HEXAGON 6 | 7 | field(:NOP, 0) 8 | field(:HEXAGON, 1) 9 | end 10 | 11 | defmodule Tensorflow.GraphTransferNodeInput do 12 | @moduledoc false 13 | use Protobuf, syntax: :proto3 14 | 15 | @type t :: %__MODULE__{ 16 | node_id: integer, 17 | output_port: integer 18 | } 19 | defstruct [:node_id, :output_port] 20 | 21 | field(:node_id, 1, type: :int32) 22 | field(:output_port, 2, type: :int32) 23 | end 24 | 25 | defmodule Tensorflow.GraphTransferNodeInfo do 26 | @moduledoc false 27 | use Protobuf, syntax: :proto3 28 | 29 | @type t :: %__MODULE__{ 30 | name: String.t(), 31 | node_id: integer, 32 | type_name: String.t(), 33 | soc_op_id: integer, 34 | padding_id: integer, 35 | input_count: integer, 36 | output_count: integer 37 | } 38 | defstruct [ 39 | :name, 40 | :node_id, 41 | :type_name, 42 | :soc_op_id, 43 | :padding_id, 44 | :input_count, 45 | :output_count 46 | ] 47 | 48 | field(:name, 1, type: :string) 49 | field(:node_id, 2, type: :int32) 50 | field(:type_name, 3, type: :string) 51 | field(:soc_op_id, 4, type: :int32) 52 | field(:padding_id, 5, type: :int32) 53 | field(:input_count, 6, type: :int32) 54 | field(:output_count, 7, type: :int32) 55 | end 56 | 57 | defmodule Tensorflow.GraphTransferConstNodeInfo do 58 | @moduledoc false 59 | use Protobuf, syntax: :proto3 60 | 61 | @type t :: %__MODULE__{ 62 | name: String.t(), 63 | node_id: integer, 64 | shape: [integer], 65 | data: binary, 66 | dtype: Tensorflow.DataType.t() 67 | } 68 | defstruct [:name, :node_id, :shape, :data, :dtype] 69 | 70 | field(:name, 1, type: :string) 71 | field(:node_id, 2, type: :int32) 72 | field(:shape, 3, repeated: true, type: :int64) 73 | field(:data, 4, type: :bytes) 74 | field(:dtype, 5, type: Tensorflow.DataType, enum: true) 75 | end 76 | 77 | defmodule Tensorflow.GraphTransferNodeInputInfo do 78 | @moduledoc false 79 | use Protobuf, syntax: :proto3 80 | 81 | @type t :: %__MODULE__{ 82 | node_id: integer, 83 | node_input: [Tensorflow.GraphTransferNodeInput.t()] 84 | } 85 | defstruct [:node_id, :node_input] 86 | 87 | field(:node_id, 1, type: :int32) 88 | 89 | field(:node_input, 2, 90 | repeated: true, 91 | type: Tensorflow.GraphTransferNodeInput 92 | ) 93 | end 94 | 95 | defmodule Tensorflow.GraphTransferNodeOutputInfo do 96 | @moduledoc false 97 | use Protobuf, syntax: :proto3 98 | 99 | @type t :: %__MODULE__{ 100 | node_id: integer, 101 | max_byte_size: [integer] 102 | } 103 | defstruct [:node_id, :max_byte_size] 104 | 105 | field(:node_id, 1, type: :int32) 106 | field(:max_byte_size, 2, repeated: true, type: :int32) 107 | end 108 | 109 | defmodule Tensorflow.GraphTransferGraphInputNodeInfo do 110 | @moduledoc false 111 | use Protobuf, syntax: :proto3 112 | 113 | @type t :: %__MODULE__{ 114 | name: String.t(), 115 | shape: [integer], 116 | dtype: Tensorflow.DataType.t() 117 | } 118 | defstruct [:name, :shape, :dtype] 119 | 120 | field(:name, 1, type: :string) 121 | field(:shape, 2, repeated: true, type: :int64) 122 | field(:dtype, 3, type: Tensorflow.DataType, enum: true) 123 | end 124 | 125 | defmodule Tensorflow.GraphTransferGraphOutputNodeInfo do 126 | @moduledoc false 127 | use Protobuf, syntax: :proto3 128 | 129 | @type t :: %__MODULE__{ 130 | name: String.t(), 131 | shape: [integer], 132 | dtype: Tensorflow.DataType.t() 133 | } 134 | defstruct [:name, :shape, :dtype] 135 | 136 | field(:name, 1, type: :string) 137 | field(:shape, 2, repeated: true, type: :int64) 138 | field(:dtype, 3, type: Tensorflow.DataType, enum: true) 139 | end 140 | 141 | defmodule Tensorflow.GraphTransferInfo do 142 | @moduledoc false 143 | use Protobuf, syntax: :proto3 144 | 145 | @type t :: %__MODULE__{ 146 | node_info: [Tensorflow.GraphTransferNodeInfo.t()], 147 | const_node_info: [Tensorflow.GraphTransferConstNodeInfo.t()], 148 | node_input_info: [Tensorflow.GraphTransferNodeInputInfo.t()], 149 | node_output_info: [Tensorflow.GraphTransferNodeOutputInfo.t()], 150 | graph_input_node_info: [ 151 | Tensorflow.GraphTransferGraphInputNodeInfo.t() 152 | ], 153 | graph_output_node_info: [ 154 | Tensorflow.GraphTransferGraphOutputNodeInfo.t() 155 | ], 156 | destination: Tensorflow.GraphTransferInfo.Destination.t() 157 | } 158 | defstruct [ 159 | :node_info, 160 | :const_node_info, 161 | :node_input_info, 162 | :node_output_info, 163 | :graph_input_node_info, 164 | :graph_output_node_info, 165 | :destination 166 | ] 167 | 168 | field(:node_info, 1, repeated: true, type: Tensorflow.GraphTransferNodeInfo) 169 | 170 | field(:const_node_info, 2, 171 | repeated: true, 172 | type: Tensorflow.GraphTransferConstNodeInfo 173 | ) 174 | 175 | field(:node_input_info, 3, 176 | repeated: true, 177 | type: Tensorflow.GraphTransferNodeInputInfo 178 | ) 179 | 180 | field(:node_output_info, 4, 181 | repeated: true, 182 | type: Tensorflow.GraphTransferNodeOutputInfo 183 | ) 184 | 185 | field(:graph_input_node_info, 5, 186 | repeated: true, 187 | type: Tensorflow.GraphTransferGraphInputNodeInfo 188 | ) 189 | 190 | field(:graph_output_node_info, 6, 191 | repeated: true, 192 | type: Tensorflow.GraphTransferGraphOutputNodeInfo 193 | ) 194 | 195 | field(:destination, 7, 196 | type: Tensorflow.GraphTransferInfo.Destination, 197 | enum: true 198 | ) 199 | end 200 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/kernel_def.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.KernelDef.AttrConstraint do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | name: String.t(), 7 | allowed_values: Tensorflow.AttrValue.t() | nil 8 | } 9 | defstruct [:name, :allowed_values] 10 | 11 | field(:name, 1, type: :string) 12 | field(:allowed_values, 2, type: Tensorflow.AttrValue) 13 | end 14 | 15 | defmodule Tensorflow.KernelDef do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | op: String.t(), 21 | device_type: String.t(), 22 | constraint: [Tensorflow.KernelDef.AttrConstraint.t()], 23 | host_memory_arg: [String.t()], 24 | label: String.t(), 25 | priority: integer 26 | } 27 | defstruct [ 28 | :op, 29 | :device_type, 30 | :constraint, 31 | :host_memory_arg, 32 | :label, 33 | :priority 34 | ] 35 | 36 | field(:op, 1, type: :string) 37 | field(:device_type, 2, type: :string) 38 | 39 | field(:constraint, 3, 40 | repeated: true, 41 | type: Tensorflow.KernelDef.AttrConstraint 42 | ) 43 | 44 | field(:host_memory_arg, 4, repeated: true, type: :string) 45 | field(:label, 5, type: :string) 46 | field(:priority, 6, type: :int32) 47 | end 48 | 49 | defmodule Tensorflow.KernelList do 50 | @moduledoc false 51 | use Protobuf, syntax: :proto3 52 | 53 | @type t :: %__MODULE__{ 54 | kernel: [Tensorflow.KernelDef.t()] 55 | } 56 | defstruct [:kernel] 57 | 58 | field(:kernel, 1, repeated: true, type: Tensorflow.KernelDef) 59 | end 60 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/log_memory.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.MemoryLogStep do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | step_id: integer, 7 | handle: String.t() 8 | } 9 | defstruct [:step_id, :handle] 10 | 11 | field(:step_id, 1, type: :int64) 12 | field(:handle, 2, type: :string) 13 | end 14 | 15 | defmodule Tensorflow.MemoryLogTensorAllocation do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | step_id: integer, 21 | kernel_name: String.t(), 22 | tensor: Tensorflow.TensorDescription.t() | nil 23 | } 24 | defstruct [:step_id, :kernel_name, :tensor] 25 | 26 | field(:step_id, 1, type: :int64) 27 | field(:kernel_name, 2, type: :string) 28 | field(:tensor, 3, type: Tensorflow.TensorDescription) 29 | end 30 | 31 | defmodule Tensorflow.MemoryLogTensorDeallocation do 32 | @moduledoc false 33 | use Protobuf, syntax: :proto3 34 | 35 | @type t :: %__MODULE__{ 36 | allocation_id: integer, 37 | allocator_name: String.t() 38 | } 39 | defstruct [:allocation_id, :allocator_name] 40 | 41 | field(:allocation_id, 1, type: :int64) 42 | field(:allocator_name, 2, type: :string) 43 | end 44 | 45 | defmodule Tensorflow.MemoryLogTensorOutput do 46 | @moduledoc false 47 | use Protobuf, syntax: :proto3 48 | 49 | @type t :: %__MODULE__{ 50 | step_id: integer, 51 | kernel_name: String.t(), 52 | index: integer, 53 | tensor: Tensorflow.TensorDescription.t() | nil 54 | } 55 | defstruct [:step_id, :kernel_name, :index, :tensor] 56 | 57 | field(:step_id, 1, type: :int64) 58 | field(:kernel_name, 2, type: :string) 59 | field(:index, 3, type: :int32) 60 | field(:tensor, 4, type: Tensorflow.TensorDescription) 61 | end 62 | 63 | defmodule Tensorflow.MemoryLogRawAllocation do 64 | @moduledoc false 65 | use Protobuf, syntax: :proto3 66 | 67 | @type t :: %__MODULE__{ 68 | step_id: integer, 69 | operation: String.t(), 70 | num_bytes: integer, 71 | ptr: non_neg_integer, 72 | allocation_id: integer, 73 | allocator_name: String.t() 74 | } 75 | defstruct [ 76 | :step_id, 77 | :operation, 78 | :num_bytes, 79 | :ptr, 80 | :allocation_id, 81 | :allocator_name 82 | ] 83 | 84 | field(:step_id, 1, type: :int64) 85 | field(:operation, 2, type: :string) 86 | field(:num_bytes, 3, type: :int64) 87 | field(:ptr, 4, type: :uint64) 88 | field(:allocation_id, 5, type: :int64) 89 | field(:allocator_name, 6, type: :string) 90 | end 91 | 92 | defmodule Tensorflow.MemoryLogRawDeallocation do 93 | @moduledoc false 94 | use Protobuf, syntax: :proto3 95 | 96 | @type t :: %__MODULE__{ 97 | step_id: integer, 98 | operation: String.t(), 99 | allocation_id: integer, 100 | allocator_name: String.t(), 101 | deferred: boolean 102 | } 103 | defstruct [:step_id, :operation, :allocation_id, :allocator_name, :deferred] 104 | 105 | field(:step_id, 1, type: :int64) 106 | field(:operation, 2, type: :string) 107 | field(:allocation_id, 3, type: :int64) 108 | field(:allocator_name, 4, type: :string) 109 | field(:deferred, 5, type: :bool) 110 | end 111 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/node_def.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.NodeDef.AttrEntry do 2 | @moduledoc false 3 | use Protobuf, map: true, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | key: String.t(), 7 | value: Tensorflow.AttrValue.t() | nil 8 | } 9 | defstruct [:key, :value] 10 | 11 | field(:key, 1, type: :string) 12 | field(:value, 2, type: Tensorflow.AttrValue) 13 | end 14 | 15 | defmodule Tensorflow.NodeDef.ExperimentalDebugInfo do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | original_node_names: [String.t()], 21 | original_func_names: [String.t()] 22 | } 23 | defstruct [:original_node_names, :original_func_names] 24 | 25 | field(:original_node_names, 1, repeated: true, type: :string) 26 | field(:original_func_names, 2, repeated: true, type: :string) 27 | end 28 | 29 | defmodule Tensorflow.NodeDef do 30 | @moduledoc false 31 | use Protobuf, syntax: :proto3 32 | 33 | @type t :: %__MODULE__{ 34 | name: String.t(), 35 | op: String.t(), 36 | input: [String.t()], 37 | device: String.t(), 38 | attr: %{String.t() => Tensorflow.AttrValue.t() | nil}, 39 | experimental_debug_info: 40 | Tensorflow.NodeDef.ExperimentalDebugInfo.t() | nil 41 | } 42 | defstruct [:name, :op, :input, :device, :attr, :experimental_debug_info] 43 | 44 | field(:name, 1, type: :string) 45 | field(:op, 2, type: :string) 46 | field(:input, 3, repeated: true, type: :string) 47 | field(:device, 4, type: :string) 48 | 49 | field(:attr, 5, 50 | repeated: true, 51 | type: Tensorflow.NodeDef.AttrEntry, 52 | map: true 53 | ) 54 | 55 | field(:experimental_debug_info, 6, 56 | type: Tensorflow.NodeDef.ExperimentalDebugInfo 57 | ) 58 | end 59 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/op_def.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.OpDef.ArgDef do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | name: String.t(), 7 | description: String.t(), 8 | type: Tensorflow.DataType.t(), 9 | type_attr: String.t(), 10 | number_attr: String.t(), 11 | type_list_attr: String.t(), 12 | is_ref: boolean 13 | } 14 | defstruct [ 15 | :name, 16 | :description, 17 | :type, 18 | :type_attr, 19 | :number_attr, 20 | :type_list_attr, 21 | :is_ref 22 | ] 23 | 24 | field(:name, 1, type: :string) 25 | field(:description, 2, type: :string) 26 | field(:type, 3, type: Tensorflow.DataType, enum: true) 27 | field(:type_attr, 4, type: :string) 28 | field(:number_attr, 5, type: :string) 29 | field(:type_list_attr, 6, type: :string) 30 | field(:is_ref, 16, type: :bool) 31 | end 32 | 33 | defmodule Tensorflow.OpDef.AttrDef do 34 | @moduledoc false 35 | use Protobuf, syntax: :proto3 36 | 37 | @type t :: %__MODULE__{ 38 | name: String.t(), 39 | type: String.t(), 40 | default_value: Tensorflow.AttrValue.t() | nil, 41 | description: String.t(), 42 | has_minimum: boolean, 43 | minimum: integer, 44 | allowed_values: Tensorflow.AttrValue.t() | nil 45 | } 46 | defstruct [ 47 | :name, 48 | :type, 49 | :default_value, 50 | :description, 51 | :has_minimum, 52 | :minimum, 53 | :allowed_values 54 | ] 55 | 56 | field(:name, 1, type: :string) 57 | field(:type, 2, type: :string) 58 | field(:default_value, 3, type: Tensorflow.AttrValue) 59 | field(:description, 4, type: :string) 60 | field(:has_minimum, 5, type: :bool) 61 | field(:minimum, 6, type: :int64) 62 | field(:allowed_values, 7, type: Tensorflow.AttrValue) 63 | end 64 | 65 | defmodule Tensorflow.OpDef do 66 | @moduledoc false 67 | use Protobuf, syntax: :proto3 68 | 69 | @type t :: %__MODULE__{ 70 | name: String.t(), 71 | input_arg: [Tensorflow.OpDef.ArgDef.t()], 72 | output_arg: [Tensorflow.OpDef.ArgDef.t()], 73 | control_output: [String.t()], 74 | attr: [Tensorflow.OpDef.AttrDef.t()], 75 | deprecation: Tensorflow.OpDeprecation.t() | nil, 76 | summary: String.t(), 77 | description: String.t(), 78 | is_commutative: boolean, 79 | is_aggregate: boolean, 80 | is_stateful: boolean, 81 | allows_uninitialized_input: boolean 82 | } 83 | defstruct [ 84 | :name, 85 | :input_arg, 86 | :output_arg, 87 | :control_output, 88 | :attr, 89 | :deprecation, 90 | :summary, 91 | :description, 92 | :is_commutative, 93 | :is_aggregate, 94 | :is_stateful, 95 | :allows_uninitialized_input 96 | ] 97 | 98 | field(:name, 1, type: :string) 99 | field(:input_arg, 2, repeated: true, type: Tensorflow.OpDef.ArgDef) 100 | field(:output_arg, 3, repeated: true, type: Tensorflow.OpDef.ArgDef) 101 | field(:control_output, 20, repeated: true, type: :string) 102 | field(:attr, 4, repeated: true, type: Tensorflow.OpDef.AttrDef) 103 | field(:deprecation, 8, type: Tensorflow.OpDeprecation) 104 | field(:summary, 5, type: :string) 105 | field(:description, 6, type: :string) 106 | field(:is_commutative, 18, type: :bool) 107 | field(:is_aggregate, 16, type: :bool) 108 | field(:is_stateful, 17, type: :bool) 109 | field(:allows_uninitialized_input, 19, type: :bool) 110 | end 111 | 112 | defmodule Tensorflow.OpDeprecation do 113 | @moduledoc false 114 | use Protobuf, syntax: :proto3 115 | 116 | @type t :: %__MODULE__{ 117 | version: integer, 118 | explanation: String.t() 119 | } 120 | defstruct [:version, :explanation] 121 | 122 | field(:version, 1, type: :int32) 123 | field(:explanation, 2, type: :string) 124 | end 125 | 126 | defmodule Tensorflow.OpList do 127 | @moduledoc false 128 | use Protobuf, syntax: :proto3 129 | 130 | @type t :: %__MODULE__{ 131 | op: [Tensorflow.OpDef.t()] 132 | } 133 | defstruct [:op] 134 | 135 | field(:op, 1, repeated: true, type: Tensorflow.OpDef) 136 | end 137 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/reader_base.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.ReaderBaseState do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | work_started: integer, 7 | work_finished: integer, 8 | num_records_produced: integer, 9 | current_work: binary 10 | } 11 | defstruct [ 12 | :work_started, 13 | :work_finished, 14 | :num_records_produced, 15 | :current_work 16 | ] 17 | 18 | field(:work_started, 1, type: :int64) 19 | field(:work_finished, 2, type: :int64) 20 | field(:num_records_produced, 3, type: :int64) 21 | field(:current_work, 4, type: :bytes) 22 | end 23 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/remote_fused_graph_execute_info.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.RemoteFusedGraphExecuteInfo.TensorShapeTypeProto do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | dtype: Tensorflow.DataType.t(), 7 | shape: Tensorflow.TensorShapeProto.t() | nil 8 | } 9 | defstruct [:dtype, :shape] 10 | 11 | field(:dtype, 1, type: Tensorflow.DataType, enum: true) 12 | field(:shape, 2, type: Tensorflow.TensorShapeProto) 13 | end 14 | 15 | defmodule Tensorflow.RemoteFusedGraphExecuteInfo do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | remote_graph: Tensorflow.GraphDef.t() | nil, 21 | graph_input_node_name: [String.t()], 22 | graph_output_node_name: [String.t()], 23 | executor_name: String.t(), 24 | serialized_executor_parameters: binary, 25 | default_graph_input_tensor_shape: [ 26 | Tensorflow.RemoteFusedGraphExecuteInfo.TensorShapeTypeProto.t() 27 | ], 28 | default_graph_output_tensor_shape: [ 29 | Tensorflow.RemoteFusedGraphExecuteInfo.TensorShapeTypeProto.t() 30 | ] 31 | } 32 | defstruct [ 33 | :remote_graph, 34 | :graph_input_node_name, 35 | :graph_output_node_name, 36 | :executor_name, 37 | :serialized_executor_parameters, 38 | :default_graph_input_tensor_shape, 39 | :default_graph_output_tensor_shape 40 | ] 41 | 42 | field(:remote_graph, 1, type: Tensorflow.GraphDef) 43 | field(:graph_input_node_name, 2, repeated: true, type: :string) 44 | field(:graph_output_node_name, 3, repeated: true, type: :string) 45 | field(:executor_name, 4, type: :string) 46 | field(:serialized_executor_parameters, 5, type: :bytes) 47 | 48 | field(:default_graph_input_tensor_shape, 6, 49 | repeated: true, 50 | type: Tensorflow.RemoteFusedGraphExecuteInfo.TensorShapeTypeProto 51 | ) 52 | 53 | field(:default_graph_output_tensor_shape, 7, 54 | repeated: true, 55 | type: Tensorflow.RemoteFusedGraphExecuteInfo.TensorShapeTypeProto 56 | ) 57 | end 58 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/resource_handle.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.ResourceHandleProto.DtypeAndShape do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | dtype: Tensorflow.DataType.t(), 7 | shape: Tensorflow.TensorShapeProto.t() | nil 8 | } 9 | defstruct [:dtype, :shape] 10 | 11 | field(:dtype, 1, type: Tensorflow.DataType, enum: true) 12 | field(:shape, 2, type: Tensorflow.TensorShapeProto) 13 | end 14 | 15 | defmodule Tensorflow.ResourceHandleProto do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | device: String.t(), 21 | container: String.t(), 22 | name: String.t(), 23 | hash_code: non_neg_integer, 24 | maybe_type_name: String.t(), 25 | dtypes_and_shapes: [ 26 | Tensorflow.ResourceHandleProto.DtypeAndShape.t() 27 | ] 28 | } 29 | defstruct [ 30 | :device, 31 | :container, 32 | :name, 33 | :hash_code, 34 | :maybe_type_name, 35 | :dtypes_and_shapes 36 | ] 37 | 38 | field(:device, 1, type: :string) 39 | field(:container, 2, type: :string) 40 | field(:name, 3, type: :string) 41 | field(:hash_code, 4, type: :uint64) 42 | field(:maybe_type_name, 5, type: :string) 43 | 44 | field(:dtypes_and_shapes, 6, 45 | repeated: true, 46 | type: Tensorflow.ResourceHandleProto.DtypeAndShape 47 | ) 48 | end 49 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/step_stats.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.AllocationRecord do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | alloc_micros: integer, 7 | alloc_bytes: integer 8 | } 9 | defstruct [:alloc_micros, :alloc_bytes] 10 | 11 | field(:alloc_micros, 1, type: :int64) 12 | field(:alloc_bytes, 2, type: :int64) 13 | end 14 | 15 | defmodule Tensorflow.AllocatorMemoryUsed do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | allocator_name: String.t(), 21 | total_bytes: integer, 22 | peak_bytes: integer, 23 | live_bytes: integer, 24 | allocation_records: [Tensorflow.AllocationRecord.t()], 25 | allocator_bytes_in_use: integer 26 | } 27 | defstruct [ 28 | :allocator_name, 29 | :total_bytes, 30 | :peak_bytes, 31 | :live_bytes, 32 | :allocation_records, 33 | :allocator_bytes_in_use 34 | ] 35 | 36 | field(:allocator_name, 1, type: :string) 37 | field(:total_bytes, 2, type: :int64) 38 | field(:peak_bytes, 3, type: :int64) 39 | field(:live_bytes, 4, type: :int64) 40 | 41 | field(:allocation_records, 6, 42 | repeated: true, 43 | type: Tensorflow.AllocationRecord 44 | ) 45 | 46 | field(:allocator_bytes_in_use, 5, type: :int64) 47 | end 48 | 49 | defmodule Tensorflow.NodeOutput do 50 | @moduledoc false 51 | use Protobuf, syntax: :proto3 52 | 53 | @type t :: %__MODULE__{ 54 | slot: integer, 55 | tensor_description: Tensorflow.TensorDescription.t() | nil 56 | } 57 | defstruct [:slot, :tensor_description] 58 | 59 | field(:slot, 1, type: :int32) 60 | field(:tensor_description, 3, type: Tensorflow.TensorDescription) 61 | end 62 | 63 | defmodule Tensorflow.MemoryStats do 64 | @moduledoc false 65 | use Protobuf, syntax: :proto3 66 | 67 | @type t :: %__MODULE__{ 68 | temp_memory_size: integer, 69 | persistent_memory_size: integer, 70 | persistent_tensor_alloc_ids: [integer], 71 | device_temp_memory_size: integer, 72 | device_persistent_memory_size: integer, 73 | device_persistent_tensor_alloc_ids: [integer] 74 | } 75 | defstruct [ 76 | :temp_memory_size, 77 | :persistent_memory_size, 78 | :persistent_tensor_alloc_ids, 79 | :device_temp_memory_size, 80 | :device_persistent_memory_size, 81 | :device_persistent_tensor_alloc_ids 82 | ] 83 | 84 | field(:temp_memory_size, 1, type: :int64) 85 | field(:persistent_memory_size, 3, type: :int64) 86 | field(:persistent_tensor_alloc_ids, 5, repeated: true, type: :int64) 87 | field(:device_temp_memory_size, 2, type: :int64, deprecated: true) 88 | field(:device_persistent_memory_size, 4, type: :int64, deprecated: true) 89 | 90 | field(:device_persistent_tensor_alloc_ids, 6, 91 | repeated: true, 92 | type: :int64, 93 | deprecated: true 94 | ) 95 | end 96 | 97 | defmodule Tensorflow.NodeExecStats do 98 | @moduledoc false 99 | use Protobuf, syntax: :proto3 100 | 101 | @type t :: %__MODULE__{ 102 | node_name: String.t(), 103 | all_start_micros: integer, 104 | op_start_rel_micros: integer, 105 | op_end_rel_micros: integer, 106 | all_end_rel_micros: integer, 107 | memory: [Tensorflow.AllocatorMemoryUsed.t()], 108 | output: [Tensorflow.NodeOutput.t()], 109 | timeline_label: String.t(), 110 | scheduled_micros: integer, 111 | thread_id: non_neg_integer, 112 | referenced_tensor: [Tensorflow.AllocationDescription.t()], 113 | memory_stats: Tensorflow.MemoryStats.t() | nil, 114 | all_start_nanos: integer, 115 | op_start_rel_nanos: integer, 116 | op_end_rel_nanos: integer, 117 | all_end_rel_nanos: integer, 118 | scheduled_nanos: integer 119 | } 120 | defstruct [ 121 | :node_name, 122 | :all_start_micros, 123 | :op_start_rel_micros, 124 | :op_end_rel_micros, 125 | :all_end_rel_micros, 126 | :memory, 127 | :output, 128 | :timeline_label, 129 | :scheduled_micros, 130 | :thread_id, 131 | :referenced_tensor, 132 | :memory_stats, 133 | :all_start_nanos, 134 | :op_start_rel_nanos, 135 | :op_end_rel_nanos, 136 | :all_end_rel_nanos, 137 | :scheduled_nanos 138 | ] 139 | 140 | field(:node_name, 1, type: :string) 141 | field(:all_start_micros, 2, type: :int64) 142 | field(:op_start_rel_micros, 3, type: :int64) 143 | field(:op_end_rel_micros, 4, type: :int64) 144 | field(:all_end_rel_micros, 5, type: :int64) 145 | field(:memory, 6, repeated: true, type: Tensorflow.AllocatorMemoryUsed) 146 | field(:output, 7, repeated: true, type: Tensorflow.NodeOutput) 147 | field(:timeline_label, 8, type: :string) 148 | field(:scheduled_micros, 9, type: :int64) 149 | field(:thread_id, 10, type: :uint32) 150 | 151 | field(:referenced_tensor, 11, 152 | repeated: true, 153 | type: Tensorflow.AllocationDescription 154 | ) 155 | 156 | field(:memory_stats, 12, type: Tensorflow.MemoryStats) 157 | field(:all_start_nanos, 13, type: :int64) 158 | field(:op_start_rel_nanos, 14, type: :int64) 159 | field(:op_end_rel_nanos, 15, type: :int64) 160 | field(:all_end_rel_nanos, 16, type: :int64) 161 | field(:scheduled_nanos, 17, type: :int64) 162 | end 163 | 164 | defmodule Tensorflow.DeviceStepStats.ThreadNamesEntry do 165 | @moduledoc false 166 | use Protobuf, map: true, syntax: :proto3 167 | 168 | @type t :: %__MODULE__{ 169 | key: non_neg_integer, 170 | value: String.t() 171 | } 172 | defstruct [:key, :value] 173 | 174 | field(:key, 1, type: :uint32) 175 | field(:value, 2, type: :string) 176 | end 177 | 178 | defmodule Tensorflow.DeviceStepStats do 179 | @moduledoc false 180 | use Protobuf, syntax: :proto3 181 | 182 | @type t :: %__MODULE__{ 183 | device: String.t(), 184 | node_stats: [Tensorflow.NodeExecStats.t()], 185 | thread_names: %{non_neg_integer => String.t()} 186 | } 187 | defstruct [:device, :node_stats, :thread_names] 188 | 189 | field(:device, 1, type: :string) 190 | field(:node_stats, 2, repeated: true, type: Tensorflow.NodeExecStats) 191 | 192 | field(:thread_names, 3, 193 | repeated: true, 194 | type: Tensorflow.DeviceStepStats.ThreadNamesEntry, 195 | map: true 196 | ) 197 | end 198 | 199 | defmodule Tensorflow.StepStats do 200 | @moduledoc false 201 | use Protobuf, syntax: :proto3 202 | 203 | @type t :: %__MODULE__{ 204 | dev_stats: [Tensorflow.DeviceStepStats.t()] 205 | } 206 | defstruct [:dev_stats] 207 | 208 | field(:dev_stats, 1, repeated: true, type: Tensorflow.DeviceStepStats) 209 | end 210 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/summary.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.DataClass do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: 6 | integer 7 | | :DATA_CLASS_UNKNOWN 8 | | :DATA_CLASS_SCALAR 9 | | :DATA_CLASS_TENSOR 10 | | :DATA_CLASS_BLOB_SEQUENCE 11 | 12 | field(:DATA_CLASS_UNKNOWN, 0) 13 | field(:DATA_CLASS_SCALAR, 1) 14 | field(:DATA_CLASS_TENSOR, 2) 15 | field(:DATA_CLASS_BLOB_SEQUENCE, 3) 16 | end 17 | 18 | defmodule Tensorflow.SummaryDescription do 19 | @moduledoc false 20 | use Protobuf, syntax: :proto3 21 | 22 | @type t :: %__MODULE__{ 23 | type_hint: String.t() 24 | } 25 | defstruct [:type_hint] 26 | 27 | field(:type_hint, 1, type: :string) 28 | end 29 | 30 | defmodule Tensorflow.HistogramProto do 31 | @moduledoc false 32 | use Protobuf, syntax: :proto3 33 | 34 | @type t :: %__MODULE__{ 35 | min: float | :infinity | :negative_infinity | :nan, 36 | max: float | :infinity | :negative_infinity | :nan, 37 | num: float | :infinity | :negative_infinity | :nan, 38 | sum: float | :infinity | :negative_infinity | :nan, 39 | sum_squares: float | :infinity | :negative_infinity | :nan, 40 | bucket_limit: [float | :infinity | :negative_infinity | :nan], 41 | bucket: [float | :infinity | :negative_infinity | :nan] 42 | } 43 | defstruct [:min, :max, :num, :sum, :sum_squares, :bucket_limit, :bucket] 44 | 45 | field(:min, 1, type: :double) 46 | field(:max, 2, type: :double) 47 | field(:num, 3, type: :double) 48 | field(:sum, 4, type: :double) 49 | field(:sum_squares, 5, type: :double) 50 | field(:bucket_limit, 6, repeated: true, type: :double, packed: true) 51 | field(:bucket, 7, repeated: true, type: :double, packed: true) 52 | end 53 | 54 | defmodule Tensorflow.SummaryMetadata.PluginData do 55 | @moduledoc false 56 | use Protobuf, syntax: :proto3 57 | 58 | @type t :: %__MODULE__{ 59 | plugin_name: String.t(), 60 | content: binary 61 | } 62 | defstruct [:plugin_name, :content] 63 | 64 | field(:plugin_name, 1, type: :string) 65 | field(:content, 2, type: :bytes) 66 | end 67 | 68 | defmodule Tensorflow.SummaryMetadata do 69 | @moduledoc false 70 | use Protobuf, syntax: :proto3 71 | 72 | @type t :: %__MODULE__{ 73 | plugin_data: Tensorflow.SummaryMetadata.PluginData.t() | nil, 74 | display_name: String.t(), 75 | summary_description: String.t(), 76 | data_class: Tensorflow.DataClass.t() 77 | } 78 | defstruct [:plugin_data, :display_name, :summary_description, :data_class] 79 | 80 | field(:plugin_data, 1, type: Tensorflow.SummaryMetadata.PluginData) 81 | field(:display_name, 2, type: :string) 82 | field(:summary_description, 3, type: :string) 83 | field(:data_class, 4, type: Tensorflow.DataClass, enum: true) 84 | end 85 | 86 | defmodule Tensorflow.Summary.Image do 87 | @moduledoc false 88 | use Protobuf, syntax: :proto3 89 | 90 | @type t :: %__MODULE__{ 91 | height: integer, 92 | width: integer, 93 | colorspace: integer, 94 | encoded_image_string: binary 95 | } 96 | defstruct [:height, :width, :colorspace, :encoded_image_string] 97 | 98 | field(:height, 1, type: :int32) 99 | field(:width, 2, type: :int32) 100 | field(:colorspace, 3, type: :int32) 101 | field(:encoded_image_string, 4, type: :bytes) 102 | end 103 | 104 | defmodule Tensorflow.Summary.Audio do 105 | @moduledoc false 106 | use Protobuf, syntax: :proto3 107 | 108 | @type t :: %__MODULE__{ 109 | sample_rate: float | :infinity | :negative_infinity | :nan, 110 | num_channels: integer, 111 | length_frames: integer, 112 | encoded_audio_string: binary, 113 | content_type: String.t() 114 | } 115 | defstruct [ 116 | :sample_rate, 117 | :num_channels, 118 | :length_frames, 119 | :encoded_audio_string, 120 | :content_type 121 | ] 122 | 123 | field(:sample_rate, 1, type: :float) 124 | field(:num_channels, 2, type: :int64) 125 | field(:length_frames, 3, type: :int64) 126 | field(:encoded_audio_string, 4, type: :bytes) 127 | field(:content_type, 5, type: :string) 128 | end 129 | 130 | defmodule Tensorflow.Summary.Value do 131 | @moduledoc false 132 | use Protobuf, syntax: :proto3 133 | 134 | @type t :: %__MODULE__{ 135 | value: {atom, any}, 136 | node_name: String.t(), 137 | tag: String.t(), 138 | metadata: Tensorflow.SummaryMetadata.t() | nil 139 | } 140 | defstruct [:value, :node_name, :tag, :metadata] 141 | 142 | oneof(:value, 0) 143 | field(:node_name, 7, type: :string) 144 | field(:tag, 1, type: :string) 145 | field(:metadata, 9, type: Tensorflow.SummaryMetadata) 146 | field(:simple_value, 2, type: :float, oneof: 0) 147 | field(:obsolete_old_style_histogram, 3, type: :bytes, oneof: 0) 148 | field(:image, 4, type: Tensorflow.Summary.Image, oneof: 0) 149 | field(:histo, 5, type: Tensorflow.HistogramProto, oneof: 0) 150 | field(:audio, 6, type: Tensorflow.Summary.Audio, oneof: 0) 151 | field(:tensor, 8, type: Tensorflow.TensorProto, oneof: 0) 152 | end 153 | 154 | defmodule Tensorflow.Summary do 155 | @moduledoc false 156 | use Protobuf, syntax: :proto3 157 | 158 | @type t :: %__MODULE__{ 159 | value: [Tensorflow.Summary.Value.t()] 160 | } 161 | defstruct [:value] 162 | 163 | field(:value, 1, repeated: true, type: Tensorflow.Summary.Value) 164 | end 165 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/tensor.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.TensorProto do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | dtype: Tensorflow.DataType.t(), 7 | tensor_shape: Tensorflow.TensorShapeProto.t() | nil, 8 | version_number: integer, 9 | tensor_content: binary, 10 | half_val: [integer], 11 | float_val: [float | :infinity | :negative_infinity | :nan], 12 | double_val: [float | :infinity | :negative_infinity | :nan], 13 | int_val: [integer], 14 | string_val: [binary], 15 | scomplex_val: [float | :infinity | :negative_infinity | :nan], 16 | int64_val: [integer], 17 | bool_val: [boolean], 18 | dcomplex_val: [float | :infinity | :negative_infinity | :nan], 19 | resource_handle_val: [Tensorflow.ResourceHandleProto.t()], 20 | variant_val: [Tensorflow.VariantTensorDataProto.t()], 21 | uint32_val: [non_neg_integer], 22 | uint64_val: [non_neg_integer] 23 | } 24 | defstruct [ 25 | :dtype, 26 | :tensor_shape, 27 | :version_number, 28 | :tensor_content, 29 | :half_val, 30 | :float_val, 31 | :double_val, 32 | :int_val, 33 | :string_val, 34 | :scomplex_val, 35 | :int64_val, 36 | :bool_val, 37 | :dcomplex_val, 38 | :resource_handle_val, 39 | :variant_val, 40 | :uint32_val, 41 | :uint64_val 42 | ] 43 | 44 | field(:dtype, 1, type: Tensorflow.DataType, enum: true) 45 | field(:tensor_shape, 2, type: Tensorflow.TensorShapeProto) 46 | field(:version_number, 3, type: :int32) 47 | field(:tensor_content, 4, type: :bytes) 48 | field(:half_val, 13, repeated: true, type: :int32, packed: true) 49 | field(:float_val, 5, repeated: true, type: :float, packed: true) 50 | field(:double_val, 6, repeated: true, type: :double, packed: true) 51 | field(:int_val, 7, repeated: true, type: :int32, packed: true) 52 | field(:string_val, 8, repeated: true, type: :bytes) 53 | field(:scomplex_val, 9, repeated: true, type: :float, packed: true) 54 | field(:int64_val, 10, repeated: true, type: :int64, packed: true) 55 | field(:bool_val, 11, repeated: true, type: :bool, packed: true) 56 | field(:dcomplex_val, 12, repeated: true, type: :double, packed: true) 57 | 58 | field(:resource_handle_val, 14, 59 | repeated: true, 60 | type: Tensorflow.ResourceHandleProto 61 | ) 62 | 63 | field(:variant_val, 15, 64 | repeated: true, 65 | type: Tensorflow.VariantTensorDataProto 66 | ) 67 | 68 | field(:uint32_val, 16, repeated: true, type: :uint32, packed: true) 69 | field(:uint64_val, 17, repeated: true, type: :uint64, packed: true) 70 | end 71 | 72 | defmodule Tensorflow.VariantTensorDataProto do 73 | @moduledoc false 74 | use Protobuf, syntax: :proto3 75 | 76 | @type t :: %__MODULE__{ 77 | type_name: String.t(), 78 | metadata: binary, 79 | tensors: [Tensorflow.TensorProto.t()] 80 | } 81 | defstruct [:type_name, :metadata, :tensors] 82 | 83 | field(:type_name, 1, type: :string) 84 | field(:metadata, 2, type: :bytes) 85 | field(:tensors, 3, repeated: true, type: Tensorflow.TensorProto) 86 | end 87 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/tensor_description.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.TensorDescription do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | dtype: Tensorflow.DataType.t(), 7 | shape: Tensorflow.TensorShapeProto.t() | nil, 8 | allocation_description: Tensorflow.AllocationDescription.t() | nil 9 | } 10 | defstruct [:dtype, :shape, :allocation_description] 11 | 12 | field(:dtype, 1, type: Tensorflow.DataType, enum: true) 13 | field(:shape, 2, type: Tensorflow.TensorShapeProto) 14 | field(:allocation_description, 4, type: Tensorflow.AllocationDescription) 15 | end 16 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/tensor_shape.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.TensorShapeProto.Dim do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | size: integer, 7 | name: String.t() 8 | } 9 | defstruct [:size, :name] 10 | 11 | field(:size, 1, type: :int64) 12 | field(:name, 2, type: :string) 13 | end 14 | 15 | defmodule Tensorflow.TensorShapeProto do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | dim: [Tensorflow.TensorShapeProto.Dim.t()], 21 | unknown_rank: boolean 22 | } 23 | defstruct [:dim, :unknown_rank] 24 | 25 | field(:dim, 2, repeated: true, type: Tensorflow.TensorShapeProto.Dim) 26 | field(:unknown_rank, 3, type: :bool) 27 | end 28 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/tensor_slice.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.TensorSliceProto.Extent do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | has_length: {atom, any}, 7 | start: integer 8 | } 9 | defstruct [:has_length, :start] 10 | 11 | oneof(:has_length, 0) 12 | field(:start, 1, type: :int64) 13 | field(:length, 2, type: :int64, oneof: 0) 14 | end 15 | 16 | defmodule Tensorflow.TensorSliceProto do 17 | @moduledoc false 18 | use Protobuf, syntax: :proto3 19 | 20 | @type t :: %__MODULE__{ 21 | extent: [Tensorflow.TensorSliceProto.Extent.t()] 22 | } 23 | defstruct [:extent] 24 | 25 | field(:extent, 1, repeated: true, type: Tensorflow.TensorSliceProto.Extent) 26 | end 27 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/types.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.DataType do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: 6 | integer 7 | | :DT_INVALID 8 | | :DT_FLOAT 9 | | :DT_DOUBLE 10 | | :DT_INT32 11 | | :DT_UINT8 12 | | :DT_INT16 13 | | :DT_INT8 14 | | :DT_STRING 15 | | :DT_COMPLEX64 16 | | :DT_INT64 17 | | :DT_BOOL 18 | | :DT_QINT8 19 | | :DT_QUINT8 20 | | :DT_QINT32 21 | | :DT_BFLOAT16 22 | | :DT_QINT16 23 | | :DT_QUINT16 24 | | :DT_UINT16 25 | | :DT_COMPLEX128 26 | | :DT_HALF 27 | | :DT_RESOURCE 28 | | :DT_VARIANT 29 | | :DT_UINT32 30 | | :DT_UINT64 31 | | :DT_FLOAT_REF 32 | | :DT_DOUBLE_REF 33 | | :DT_INT32_REF 34 | | :DT_UINT8_REF 35 | | :DT_INT16_REF 36 | | :DT_INT8_REF 37 | | :DT_STRING_REF 38 | | :DT_COMPLEX64_REF 39 | | :DT_INT64_REF 40 | | :DT_BOOL_REF 41 | | :DT_QINT8_REF 42 | | :DT_QUINT8_REF 43 | | :DT_QINT32_REF 44 | | :DT_BFLOAT16_REF 45 | | :DT_QINT16_REF 46 | | :DT_QUINT16_REF 47 | | :DT_UINT16_REF 48 | | :DT_COMPLEX128_REF 49 | | :DT_HALF_REF 50 | | :DT_RESOURCE_REF 51 | | :DT_VARIANT_REF 52 | | :DT_UINT32_REF 53 | | :DT_UINT64_REF 54 | 55 | field(:DT_INVALID, 0) 56 | field(:DT_FLOAT, 1) 57 | field(:DT_DOUBLE, 2) 58 | field(:DT_INT32, 3) 59 | field(:DT_UINT8, 4) 60 | field(:DT_INT16, 5) 61 | field(:DT_INT8, 6) 62 | field(:DT_STRING, 7) 63 | field(:DT_COMPLEX64, 8) 64 | field(:DT_INT64, 9) 65 | field(:DT_BOOL, 10) 66 | field(:DT_QINT8, 11) 67 | field(:DT_QUINT8, 12) 68 | field(:DT_QINT32, 13) 69 | field(:DT_BFLOAT16, 14) 70 | field(:DT_QINT16, 15) 71 | field(:DT_QUINT16, 16) 72 | field(:DT_UINT16, 17) 73 | field(:DT_COMPLEX128, 18) 74 | field(:DT_HALF, 19) 75 | field(:DT_RESOURCE, 20) 76 | field(:DT_VARIANT, 21) 77 | field(:DT_UINT32, 22) 78 | field(:DT_UINT64, 23) 79 | field(:DT_FLOAT_REF, 101) 80 | field(:DT_DOUBLE_REF, 102) 81 | field(:DT_INT32_REF, 103) 82 | field(:DT_UINT8_REF, 104) 83 | field(:DT_INT16_REF, 105) 84 | field(:DT_INT8_REF, 106) 85 | field(:DT_STRING_REF, 107) 86 | field(:DT_COMPLEX64_REF, 108) 87 | field(:DT_INT64_REF, 109) 88 | field(:DT_BOOL_REF, 110) 89 | field(:DT_QINT8_REF, 111) 90 | field(:DT_QUINT8_REF, 112) 91 | field(:DT_QINT32_REF, 113) 92 | field(:DT_BFLOAT16_REF, 114) 93 | field(:DT_QINT16_REF, 115) 94 | field(:DT_QUINT16_REF, 116) 95 | field(:DT_UINT16_REF, 117) 96 | field(:DT_COMPLEX128_REF, 118) 97 | field(:DT_HALF_REF, 119) 98 | field(:DT_RESOURCE_REF, 120) 99 | field(:DT_VARIANT_REF, 121) 100 | field(:DT_UINT32_REF, 122) 101 | field(:DT_UINT64_REF, 123) 102 | end 103 | 104 | defmodule Tensorflow.SpecializedType do 105 | @moduledoc false 106 | use Protobuf, enum: true, syntax: :proto3 107 | 108 | @type t :: integer | :ST_INVALID | :ST_TENSOR_LIST 109 | 110 | field(:ST_INVALID, 0) 111 | field(:ST_TENSOR_LIST, 1) 112 | end 113 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/variable.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.VariableSynchronization do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: 6 | integer 7 | | :VARIABLE_SYNCHRONIZATION_AUTO 8 | | :VARIABLE_SYNCHRONIZATION_NONE 9 | | :VARIABLE_SYNCHRONIZATION_ON_WRITE 10 | | :VARIABLE_SYNCHRONIZATION_ON_READ 11 | 12 | field(:VARIABLE_SYNCHRONIZATION_AUTO, 0) 13 | field(:VARIABLE_SYNCHRONIZATION_NONE, 1) 14 | field(:VARIABLE_SYNCHRONIZATION_ON_WRITE, 2) 15 | field(:VARIABLE_SYNCHRONIZATION_ON_READ, 3) 16 | end 17 | 18 | defmodule Tensorflow.VariableAggregation do 19 | @moduledoc false 20 | use Protobuf, enum: true, syntax: :proto3 21 | 22 | @type t :: 23 | integer 24 | | :VARIABLE_AGGREGATION_NONE 25 | | :VARIABLE_AGGREGATION_SUM 26 | | :VARIABLE_AGGREGATION_MEAN 27 | | :VARIABLE_AGGREGATION_ONLY_FIRST_REPLICA 28 | 29 | field(:VARIABLE_AGGREGATION_NONE, 0) 30 | field(:VARIABLE_AGGREGATION_SUM, 1) 31 | field(:VARIABLE_AGGREGATION_MEAN, 2) 32 | field(:VARIABLE_AGGREGATION_ONLY_FIRST_REPLICA, 3) 33 | end 34 | 35 | defmodule Tensorflow.VariableDef do 36 | @moduledoc false 37 | use Protobuf, syntax: :proto3 38 | 39 | @type t :: %__MODULE__{ 40 | variable_name: String.t(), 41 | initial_value_name: String.t(), 42 | initializer_name: String.t(), 43 | snapshot_name: String.t(), 44 | save_slice_info_def: Tensorflow.SaveSliceInfoDef.t() | nil, 45 | is_resource: boolean, 46 | trainable: boolean, 47 | synchronization: Tensorflow.VariableSynchronization.t(), 48 | aggregation: Tensorflow.VariableAggregation.t() 49 | } 50 | defstruct [ 51 | :variable_name, 52 | :initial_value_name, 53 | :initializer_name, 54 | :snapshot_name, 55 | :save_slice_info_def, 56 | :is_resource, 57 | :trainable, 58 | :synchronization, 59 | :aggregation 60 | ] 61 | 62 | field(:variable_name, 1, type: :string) 63 | field(:initial_value_name, 6, type: :string) 64 | field(:initializer_name, 2, type: :string) 65 | field(:snapshot_name, 3, type: :string) 66 | field(:save_slice_info_def, 4, type: Tensorflow.SaveSliceInfoDef) 67 | field(:is_resource, 5, type: :bool) 68 | field(:trainable, 7, type: :bool) 69 | 70 | field(:synchronization, 8, 71 | type: Tensorflow.VariableSynchronization, 72 | enum: true 73 | ) 74 | 75 | field(:aggregation, 9, type: Tensorflow.VariableAggregation, enum: true) 76 | end 77 | 78 | defmodule Tensorflow.SaveSliceInfoDef do 79 | @moduledoc false 80 | use Protobuf, syntax: :proto3 81 | 82 | @type t :: %__MODULE__{ 83 | full_name: String.t(), 84 | full_shape: [integer], 85 | var_offset: [integer], 86 | var_shape: [integer] 87 | } 88 | defstruct [:full_name, :full_shape, :var_offset, :var_shape] 89 | 90 | field(:full_name, 1, type: :string) 91 | field(:full_shape, 2, repeated: true, type: :int64) 92 | field(:var_offset, 3, repeated: true, type: :int64) 93 | field(:var_shape, 4, repeated: true, type: :int64) 94 | end 95 | -------------------------------------------------------------------------------- /lib/tensorflow/core/framework/versions.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.VersionDef do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | producer: integer, 7 | min_consumer: integer, 8 | bad_consumers: [integer] 9 | } 10 | defstruct [:producer, :min_consumer, :bad_consumers] 11 | 12 | field(:producer, 1, type: :int32) 13 | field(:min_consumer, 2, type: :int32) 14 | field(:bad_consumers, 3, repeated: true, type: :int32) 15 | end 16 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/autotuning.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.AutotuneResult.FailureKind do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: integer | :UNKNOWN | :REDZONE_MODIFIED | :WRONG_RESULT 6 | 7 | field(:UNKNOWN, 0) 8 | field(:REDZONE_MODIFIED, 1) 9 | field(:WRONG_RESULT, 2) 10 | end 11 | 12 | defmodule Tensorflow.CudnnVersion do 13 | @moduledoc false 14 | use Protobuf, syntax: :proto3 15 | 16 | @type t :: %__MODULE__{ 17 | major: integer, 18 | minor: integer, 19 | patch: integer 20 | } 21 | defstruct [:major, :minor, :patch] 22 | 23 | field(:major, 1, type: :int32) 24 | field(:minor, 2, type: :int32) 25 | field(:patch, 3, type: :int32) 26 | end 27 | 28 | defmodule Tensorflow.ComputeCapability do 29 | @moduledoc false 30 | use Protobuf, syntax: :proto3 31 | 32 | @type t :: %__MODULE__{ 33 | major: integer, 34 | minor: integer 35 | } 36 | defstruct [:major, :minor] 37 | 38 | field(:major, 1, type: :int32) 39 | field(:minor, 2, type: :int32) 40 | end 41 | 42 | defmodule Tensorflow.AutotuneResult.FailureResult do 43 | @moduledoc false 44 | use Protobuf, syntax: :proto3 45 | 46 | @type t :: %__MODULE__{ 47 | key: {atom, any}, 48 | kind: Tensorflow.AutotuneResult.FailureKind.t(), 49 | msg: String.t(), 50 | buffer_address: integer 51 | } 52 | defstruct [:key, :kind, :msg, :buffer_address] 53 | 54 | oneof(:key, 0) 55 | field(:kind, 1, type: Tensorflow.AutotuneResult.FailureKind, enum: true) 56 | field(:msg, 2, type: :string) 57 | 58 | field(:reference_conv, 11, type: Tensorflow.AutotuneResult.ConvKey, oneof: 0) 59 | 60 | field(:reference_gemm, 12, type: Tensorflow.AutotuneResult.GemmKey, oneof: 0) 61 | 62 | field(:buffer_address, 13, type: :int64) 63 | end 64 | 65 | defmodule Tensorflow.AutotuneResult.ConvKey do 66 | @moduledoc false 67 | use Protobuf, syntax: :proto3 68 | 69 | @type t :: %__MODULE__{ 70 | algorithm: integer, 71 | tensor_ops_enabled: boolean 72 | } 73 | defstruct [:algorithm, :tensor_ops_enabled] 74 | 75 | field(:algorithm, 1, type: :int64) 76 | field(:tensor_ops_enabled, 2, type: :bool) 77 | end 78 | 79 | defmodule Tensorflow.AutotuneResult.GemmKey do 80 | @moduledoc false 81 | use Protobuf, syntax: :proto3 82 | 83 | @type t :: %__MODULE__{ 84 | algorithm: integer 85 | } 86 | defstruct [:algorithm] 87 | 88 | field(:algorithm, 1, type: :int64) 89 | end 90 | 91 | defmodule Tensorflow.AutotuneResult do 92 | @moduledoc false 93 | use Protobuf, syntax: :proto3 94 | 95 | @type t :: %__MODULE__{ 96 | key: {atom, any}, 97 | scratch_bytes: integer, 98 | run_time: Google.Protobuf.Duration.t() | nil, 99 | failure: Tensorflow.AutotuneResult.FailureResult.t() | nil 100 | } 101 | defstruct [:key, :scratch_bytes, :run_time, :failure] 102 | 103 | oneof(:key, 0) 104 | field(:scratch_bytes, 8, type: :int64) 105 | field(:run_time, 9, type: Google.Protobuf.Duration) 106 | field(:failure, 7, type: Tensorflow.AutotuneResult.FailureResult) 107 | field(:conv, 5, type: Tensorflow.AutotuneResult.ConvKey, oneof: 0) 108 | field(:gemm, 6, type: Tensorflow.AutotuneResult.GemmKey, oneof: 0) 109 | end 110 | 111 | defmodule Tensorflow.AutotuningLog do 112 | @moduledoc false 113 | use Protobuf, syntax: :proto3 114 | 115 | @type t :: %__MODULE__{ 116 | instr: Google.Protobuf.Any.t() | nil, 117 | results: [Tensorflow.AutotuneResult.t()], 118 | cudnn_version: Tensorflow.CudnnVersion.t() | nil, 119 | compute_capability: Tensorflow.ComputeCapability.t() | nil, 120 | device_pci_bus_id: String.t(), 121 | blas_version: String.t() 122 | } 123 | defstruct [ 124 | :instr, 125 | :results, 126 | :cudnn_version, 127 | :compute_capability, 128 | :device_pci_bus_id, 129 | :blas_version 130 | ] 131 | 132 | field(:instr, 1, type: Google.Protobuf.Any) 133 | field(:results, 2, repeated: true, type: Tensorflow.AutotuneResult) 134 | field(:cudnn_version, 3, type: Tensorflow.CudnnVersion) 135 | field(:compute_capability, 4, type: Tensorflow.ComputeCapability) 136 | field(:device_pci_bus_id, 5, type: :string) 137 | field(:blas_version, 6, type: :string) 138 | end 139 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/bfc_memory_map.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.MemAllocatorStats do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | num_allocs: integer, 7 | bytes_in_use: integer, 8 | peak_bytes_in_use: integer, 9 | largest_alloc_size: integer, 10 | fragmentation_metric: float | :infinity | :negative_infinity | :nan 11 | } 12 | defstruct [ 13 | :num_allocs, 14 | :bytes_in_use, 15 | :peak_bytes_in_use, 16 | :largest_alloc_size, 17 | :fragmentation_metric 18 | ] 19 | 20 | field(:num_allocs, 1, type: :int64) 21 | field(:bytes_in_use, 2, type: :int64) 22 | field(:peak_bytes_in_use, 3, type: :int64) 23 | field(:largest_alloc_size, 4, type: :int64) 24 | field(:fragmentation_metric, 5, type: :float) 25 | end 26 | 27 | defmodule Tensorflow.MemChunk do 28 | @moduledoc false 29 | use Protobuf, syntax: :proto3 30 | 31 | @type t :: %__MODULE__{ 32 | address: non_neg_integer, 33 | size: integer, 34 | requested_size: integer, 35 | bin: integer, 36 | op_name: String.t(), 37 | freed_at_count: non_neg_integer, 38 | action_count: non_neg_integer, 39 | in_use: boolean, 40 | step_id: non_neg_integer 41 | } 42 | defstruct [ 43 | :address, 44 | :size, 45 | :requested_size, 46 | :bin, 47 | :op_name, 48 | :freed_at_count, 49 | :action_count, 50 | :in_use, 51 | :step_id 52 | ] 53 | 54 | field(:address, 1, type: :uint64) 55 | field(:size, 2, type: :int64) 56 | field(:requested_size, 3, type: :int64) 57 | field(:bin, 4, type: :int32) 58 | field(:op_name, 5, type: :string) 59 | field(:freed_at_count, 6, type: :uint64) 60 | field(:action_count, 7, type: :uint64) 61 | field(:in_use, 8, type: :bool) 62 | field(:step_id, 9, type: :uint64) 63 | end 64 | 65 | defmodule Tensorflow.BinSummary do 66 | @moduledoc false 67 | use Protobuf, syntax: :proto3 68 | 69 | @type t :: %__MODULE__{ 70 | bin: integer, 71 | total_bytes_in_use: integer, 72 | total_bytes_in_bin: integer, 73 | total_chunks_in_use: integer, 74 | total_chunks_in_bin: integer 75 | } 76 | defstruct [ 77 | :bin, 78 | :total_bytes_in_use, 79 | :total_bytes_in_bin, 80 | :total_chunks_in_use, 81 | :total_chunks_in_bin 82 | ] 83 | 84 | field(:bin, 1, type: :int32) 85 | field(:total_bytes_in_use, 2, type: :int64) 86 | field(:total_bytes_in_bin, 3, type: :int64) 87 | field(:total_chunks_in_use, 4, type: :int64) 88 | field(:total_chunks_in_bin, 5, type: :int64) 89 | end 90 | 91 | defmodule Tensorflow.SnapShot do 92 | @moduledoc false 93 | use Protobuf, syntax: :proto3 94 | 95 | @type t :: %__MODULE__{ 96 | action_count: non_neg_integer, 97 | size: integer 98 | } 99 | defstruct [:action_count, :size] 100 | 101 | field(:action_count, 1, type: :uint64) 102 | field(:size, 2, type: :int64) 103 | end 104 | 105 | defmodule Tensorflow.MemoryDump do 106 | @moduledoc false 107 | use Protobuf, syntax: :proto3 108 | 109 | @type t :: %__MODULE__{ 110 | allocator_name: String.t(), 111 | bin_summary: [Tensorflow.BinSummary.t()], 112 | chunk: [Tensorflow.MemChunk.t()], 113 | snap_shot: [Tensorflow.SnapShot.t()], 114 | stats: Tensorflow.MemAllocatorStats.t() | nil 115 | } 116 | defstruct [:allocator_name, :bin_summary, :chunk, :snap_shot, :stats] 117 | 118 | field(:allocator_name, 1, type: :string) 119 | field(:bin_summary, 2, repeated: true, type: Tensorflow.BinSummary) 120 | field(:chunk, 3, repeated: true, type: Tensorflow.MemChunk) 121 | field(:snap_shot, 4, repeated: true, type: Tensorflow.SnapShot) 122 | field(:stats, 5, type: Tensorflow.MemAllocatorStats) 123 | end 124 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/cluster.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.JobDef.TasksEntry do 2 | @moduledoc false 3 | use Protobuf, map: true, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | key: integer, 7 | value: String.t() 8 | } 9 | defstruct [:key, :value] 10 | 11 | field(:key, 1, type: :int32) 12 | field(:value, 2, type: :string) 13 | end 14 | 15 | defmodule Tensorflow.JobDef do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | name: String.t(), 21 | tasks: %{integer => String.t()} 22 | } 23 | defstruct [:name, :tasks] 24 | 25 | field(:name, 1, type: :string) 26 | 27 | field(:tasks, 2, 28 | repeated: true, 29 | type: Tensorflow.JobDef.TasksEntry, 30 | map: true 31 | ) 32 | end 33 | 34 | defmodule Tensorflow.ClusterDef do 35 | @moduledoc false 36 | use Protobuf, syntax: :proto3 37 | 38 | @type t :: %__MODULE__{ 39 | job: [Tensorflow.JobDef.t()] 40 | } 41 | defstruct [:job] 42 | 43 | field(:job, 1, repeated: true, type: Tensorflow.JobDef) 44 | end 45 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/control_flow.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.ValuesDef.ExternalValuesEntry do 2 | @moduledoc false 3 | use Protobuf, map: true, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | key: String.t(), 7 | value: String.t() 8 | } 9 | defstruct [:key, :value] 10 | 11 | field(:key, 1, type: :string) 12 | field(:value, 2, type: :string) 13 | end 14 | 15 | defmodule Tensorflow.ValuesDef do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | values: [String.t()], 21 | external_values: %{String.t() => String.t()} 22 | } 23 | defstruct [:values, :external_values] 24 | 25 | field(:values, 1, repeated: true, type: :string) 26 | 27 | field(:external_values, 2, 28 | repeated: true, 29 | type: Tensorflow.ValuesDef.ExternalValuesEntry, 30 | map: true 31 | ) 32 | end 33 | 34 | defmodule Tensorflow.ControlFlowContextDef do 35 | @moduledoc false 36 | use Protobuf, syntax: :proto3 37 | 38 | @type t :: %__MODULE__{ 39 | ctxt: {atom, any} 40 | } 41 | defstruct [:ctxt] 42 | 43 | oneof(:ctxt, 0) 44 | field(:cond_ctxt, 1, type: Tensorflow.CondContextDef, oneof: 0) 45 | field(:while_ctxt, 2, type: Tensorflow.WhileContextDef, oneof: 0) 46 | end 47 | 48 | defmodule Tensorflow.CondContextDef do 49 | @moduledoc false 50 | use Protobuf, syntax: :proto3 51 | 52 | @type t :: %__MODULE__{ 53 | context_name: String.t(), 54 | pred_name: String.t(), 55 | pivot_name: String.t(), 56 | branch: integer, 57 | values_def: Tensorflow.ValuesDef.t() | nil, 58 | nested_contexts: [Tensorflow.ControlFlowContextDef.t()] 59 | } 60 | defstruct [ 61 | :context_name, 62 | :pred_name, 63 | :pivot_name, 64 | :branch, 65 | :values_def, 66 | :nested_contexts 67 | ] 68 | 69 | field(:context_name, 1, type: :string) 70 | field(:pred_name, 2, type: :string) 71 | field(:pivot_name, 3, type: :string) 72 | field(:branch, 4, type: :int32) 73 | field(:values_def, 5, type: Tensorflow.ValuesDef) 74 | 75 | field(:nested_contexts, 6, 76 | repeated: true, 77 | type: Tensorflow.ControlFlowContextDef 78 | ) 79 | end 80 | 81 | defmodule Tensorflow.WhileContextDef do 82 | @moduledoc false 83 | use Protobuf, syntax: :proto3 84 | 85 | @type t :: %__MODULE__{ 86 | context_name: String.t(), 87 | parallel_iterations: integer, 88 | back_prop: boolean, 89 | swap_memory: boolean, 90 | pivot_name: String.t(), 91 | pivot_for_pred_name: String.t(), 92 | pivot_for_body_name: String.t(), 93 | loop_exit_names: [String.t()], 94 | loop_enter_names: [String.t()], 95 | values_def: Tensorflow.ValuesDef.t() | nil, 96 | maximum_iterations_name: String.t(), 97 | nested_contexts: [Tensorflow.ControlFlowContextDef.t()] 98 | } 99 | defstruct [ 100 | :context_name, 101 | :parallel_iterations, 102 | :back_prop, 103 | :swap_memory, 104 | :pivot_name, 105 | :pivot_for_pred_name, 106 | :pivot_for_body_name, 107 | :loop_exit_names, 108 | :loop_enter_names, 109 | :values_def, 110 | :maximum_iterations_name, 111 | :nested_contexts 112 | ] 113 | 114 | field(:context_name, 1, type: :string) 115 | field(:parallel_iterations, 2, type: :int32) 116 | field(:back_prop, 3, type: :bool) 117 | field(:swap_memory, 4, type: :bool) 118 | field(:pivot_name, 5, type: :string) 119 | field(:pivot_for_pred_name, 6, type: :string) 120 | field(:pivot_for_body_name, 7, type: :string) 121 | field(:loop_exit_names, 8, repeated: true, type: :string) 122 | field(:loop_enter_names, 10, repeated: true, type: :string) 123 | field(:values_def, 9, type: Tensorflow.ValuesDef) 124 | field(:maximum_iterations_name, 11, type: :string) 125 | 126 | field(:nested_contexts, 12, 127 | repeated: true, 128 | type: Tensorflow.ControlFlowContextDef 129 | ) 130 | end 131 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/conv_autotuning.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.ConvolutionProto do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | kind: StreamExecutor.Dnn.ConvolutionKind.t(), 7 | input: StreamExecutor.Dnn.TensorDescriptorProto.t() | nil, 8 | filter: StreamExecutor.Dnn.TensorDescriptorProto.t() | nil, 9 | output: StreamExecutor.Dnn.TensorDescriptorProto.t() | nil, 10 | conv_desc: StreamExecutor.Dnn.ConvolutionDescriptorProto.t() | nil, 11 | conv_scale: float | :infinity | :negative_infinity | :nan, 12 | side_value_scale: float | :infinity | :negative_infinity | :nan, 13 | activation: StreamExecutor.Dnn.ActivationMode.t(), 14 | input_address: integer, 15 | filter_address: integer, 16 | output_address: integer, 17 | bias_address: integer, 18 | side_input_address: integer 19 | } 20 | defstruct [ 21 | :kind, 22 | :input, 23 | :filter, 24 | :output, 25 | :conv_desc, 26 | :conv_scale, 27 | :side_value_scale, 28 | :activation, 29 | :input_address, 30 | :filter_address, 31 | :output_address, 32 | :bias_address, 33 | :side_input_address 34 | ] 35 | 36 | field(:kind, 1, type: StreamExecutor.Dnn.ConvolutionKind, enum: true) 37 | field(:input, 2, type: StreamExecutor.Dnn.TensorDescriptorProto) 38 | field(:filter, 3, type: StreamExecutor.Dnn.TensorDescriptorProto) 39 | field(:output, 4, type: StreamExecutor.Dnn.TensorDescriptorProto) 40 | field(:conv_desc, 5, type: StreamExecutor.Dnn.ConvolutionDescriptorProto) 41 | field(:conv_scale, 6, type: :double) 42 | field(:side_value_scale, 7, type: :double) 43 | field(:activation, 8, type: StreamExecutor.Dnn.ActivationMode, enum: true) 44 | field(:input_address, 9, type: :int64) 45 | field(:filter_address, 10, type: :int64) 46 | field(:output_address, 11, type: :int64) 47 | field(:bias_address, 12, type: :int64) 48 | field(:side_input_address, 13, type: :int64) 49 | end 50 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/critical_section.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.CriticalSectionDef do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | critical_section_name: String.t() 7 | } 8 | defstruct [:critical_section_name] 9 | 10 | field(:critical_section_name, 1, type: :string) 11 | end 12 | 13 | defmodule Tensorflow.CriticalSectionExecutionDef do 14 | @moduledoc false 15 | use Protobuf, syntax: :proto3 16 | 17 | @type t :: %__MODULE__{ 18 | execute_in_critical_section_name: String.t(), 19 | exclusive_resource_access: boolean 20 | } 21 | defstruct [:execute_in_critical_section_name, :exclusive_resource_access] 22 | 23 | field(:execute_in_critical_section_name, 1, type: :string) 24 | field(:exclusive_resource_access, 2, type: :bool) 25 | end 26 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/debug.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.DebugTensorWatch do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | node_name: String.t(), 7 | output_slot: integer, 8 | debug_ops: [String.t()], 9 | debug_urls: [String.t()], 10 | tolerate_debug_op_creation_failures: boolean 11 | } 12 | defstruct [ 13 | :node_name, 14 | :output_slot, 15 | :debug_ops, 16 | :debug_urls, 17 | :tolerate_debug_op_creation_failures 18 | ] 19 | 20 | field(:node_name, 1, type: :string) 21 | field(:output_slot, 2, type: :int32) 22 | field(:debug_ops, 3, repeated: true, type: :string) 23 | field(:debug_urls, 4, repeated: true, type: :string) 24 | field(:tolerate_debug_op_creation_failures, 5, type: :bool) 25 | end 26 | 27 | defmodule Tensorflow.DebugOptions do 28 | @moduledoc false 29 | use Protobuf, syntax: :proto3 30 | 31 | @type t :: %__MODULE__{ 32 | debug_tensor_watch_opts: [Tensorflow.DebugTensorWatch.t()], 33 | global_step: integer, 34 | reset_disk_byte_usage: boolean 35 | } 36 | defstruct [:debug_tensor_watch_opts, :global_step, :reset_disk_byte_usage] 37 | 38 | field(:debug_tensor_watch_opts, 4, 39 | repeated: true, 40 | type: Tensorflow.DebugTensorWatch 41 | ) 42 | 43 | field(:global_step, 10, type: :int64) 44 | field(:reset_disk_byte_usage, 11, type: :bool) 45 | end 46 | 47 | defmodule Tensorflow.DebuggedSourceFile do 48 | @moduledoc false 49 | use Protobuf, syntax: :proto3 50 | 51 | @type t :: %__MODULE__{ 52 | host: String.t(), 53 | file_path: String.t(), 54 | last_modified: integer, 55 | bytes: integer, 56 | lines: [String.t()] 57 | } 58 | defstruct [:host, :file_path, :last_modified, :bytes, :lines] 59 | 60 | field(:host, 1, type: :string) 61 | field(:file_path, 2, type: :string) 62 | field(:last_modified, 3, type: :int64) 63 | field(:bytes, 4, type: :int64) 64 | field(:lines, 5, repeated: true, type: :string) 65 | end 66 | 67 | defmodule Tensorflow.DebuggedSourceFiles do 68 | @moduledoc false 69 | use Protobuf, syntax: :proto3 70 | 71 | @type t :: %__MODULE__{ 72 | source_files: [Tensorflow.DebuggedSourceFile.t()] 73 | } 74 | defstruct [:source_files] 75 | 76 | field(:source_files, 1, repeated: true, type: Tensorflow.DebuggedSourceFile) 77 | end 78 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/debug_event.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.TensorDebugMode do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: 6 | integer 7 | | :UNSPECIFIED 8 | | :NO_TENSOR 9 | | :CURT_HEALTH 10 | | :CONCISE_HEALTH 11 | | :FULL_HEALTH 12 | | :SHAPE 13 | | :FULL_NUMERICS 14 | | :FULL_TENSOR 15 | | :REDUCE_INF_NAN_THREE_SLOTS 16 | 17 | field(:UNSPECIFIED, 0) 18 | field(:NO_TENSOR, 1) 19 | field(:CURT_HEALTH, 2) 20 | field(:CONCISE_HEALTH, 3) 21 | field(:FULL_HEALTH, 4) 22 | field(:SHAPE, 5) 23 | field(:FULL_NUMERICS, 6) 24 | field(:FULL_TENSOR, 7) 25 | field(:REDUCE_INF_NAN_THREE_SLOTS, 8) 26 | end 27 | 28 | defmodule Tensorflow.DebugEvent do 29 | @moduledoc false 30 | use Protobuf, syntax: :proto3 31 | 32 | @type t :: %__MODULE__{ 33 | what: {atom, any}, 34 | wall_time: float | :infinity | :negative_infinity | :nan, 35 | step: integer 36 | } 37 | defstruct [:what, :wall_time, :step] 38 | 39 | oneof(:what, 0) 40 | field(:wall_time, 1, type: :double) 41 | field(:step, 2, type: :int64) 42 | field(:debug_metadata, 3, type: Tensorflow.DebugMetadata, oneof: 0) 43 | field(:source_file, 4, type: Tensorflow.SourceFile, oneof: 0) 44 | field(:stack_frame_with_id, 6, type: Tensorflow.StackFrameWithId, oneof: 0) 45 | field(:graph_op_creation, 7, type: Tensorflow.GraphOpCreation, oneof: 0) 46 | field(:debugged_graph, 8, type: Tensorflow.DebuggedGraph, oneof: 0) 47 | field(:execution, 9, type: Tensorflow.Execution, oneof: 0) 48 | 49 | field(:graph_execution_trace, 10, 50 | type: Tensorflow.GraphExecutionTrace, 51 | oneof: 0 52 | ) 53 | 54 | field(:graph_id, 11, type: :string, oneof: 0) 55 | field(:debugged_device, 12, type: Tensorflow.DebuggedDevice, oneof: 0) 56 | end 57 | 58 | defmodule Tensorflow.DebugMetadata do 59 | @moduledoc false 60 | use Protobuf, syntax: :proto3 61 | 62 | @type t :: %__MODULE__{ 63 | tensorflow_version: String.t(), 64 | file_version: String.t(), 65 | tfdbg_run_id: String.t() 66 | } 67 | defstruct [:tensorflow_version, :file_version, :tfdbg_run_id] 68 | 69 | field(:tensorflow_version, 1, type: :string) 70 | field(:file_version, 2, type: :string) 71 | field(:tfdbg_run_id, 3, type: :string) 72 | end 73 | 74 | defmodule Tensorflow.SourceFile do 75 | @moduledoc false 76 | use Protobuf, syntax: :proto3 77 | 78 | @type t :: %__MODULE__{ 79 | file_path: String.t(), 80 | host_name: String.t(), 81 | lines: [String.t()] 82 | } 83 | defstruct [:file_path, :host_name, :lines] 84 | 85 | field(:file_path, 1, type: :string) 86 | field(:host_name, 2, type: :string) 87 | field(:lines, 3, repeated: true, type: :string) 88 | end 89 | 90 | defmodule Tensorflow.StackFrameWithId do 91 | @moduledoc false 92 | use Protobuf, syntax: :proto3 93 | 94 | @type t :: %__MODULE__{ 95 | id: String.t(), 96 | file_line_col: Tensorflow.GraphDebugInfo.FileLineCol.t() | nil 97 | } 98 | defstruct [:id, :file_line_col] 99 | 100 | field(:id, 1, type: :string) 101 | field(:file_line_col, 2, type: Tensorflow.GraphDebugInfo.FileLineCol) 102 | end 103 | 104 | defmodule Tensorflow.CodeLocation do 105 | @moduledoc false 106 | use Protobuf, syntax: :proto3 107 | 108 | @type t :: %__MODULE__{ 109 | host_name: String.t(), 110 | stack_frame_ids: [String.t()] 111 | } 112 | defstruct [:host_name, :stack_frame_ids] 113 | 114 | field(:host_name, 1, type: :string) 115 | field(:stack_frame_ids, 2, repeated: true, type: :string) 116 | end 117 | 118 | defmodule Tensorflow.GraphOpCreation do 119 | @moduledoc false 120 | use Protobuf, syntax: :proto3 121 | 122 | @type t :: %__MODULE__{ 123 | op_type: String.t(), 124 | op_name: String.t(), 125 | graph_name: String.t(), 126 | graph_id: String.t(), 127 | device_name: String.t(), 128 | input_names: [String.t()], 129 | num_outputs: integer, 130 | code_location: Tensorflow.CodeLocation.t() | nil, 131 | output_tensor_ids: [integer] 132 | } 133 | defstruct [ 134 | :op_type, 135 | :op_name, 136 | :graph_name, 137 | :graph_id, 138 | :device_name, 139 | :input_names, 140 | :num_outputs, 141 | :code_location, 142 | :output_tensor_ids 143 | ] 144 | 145 | field(:op_type, 1, type: :string) 146 | field(:op_name, 2, type: :string) 147 | field(:graph_name, 3, type: :string) 148 | field(:graph_id, 4, type: :string) 149 | field(:device_name, 5, type: :string) 150 | field(:input_names, 6, repeated: true, type: :string) 151 | field(:num_outputs, 7, type: :int32) 152 | field(:code_location, 8, type: Tensorflow.CodeLocation) 153 | field(:output_tensor_ids, 9, repeated: true, type: :int32) 154 | end 155 | 156 | defmodule Tensorflow.DebuggedGraph do 157 | @moduledoc false 158 | use Protobuf, syntax: :proto3 159 | 160 | @type t :: %__MODULE__{ 161 | graph_id: String.t(), 162 | graph_name: String.t(), 163 | instrumented_ops: [String.t()], 164 | original_graph_def: binary, 165 | instrumented_graph_def: binary, 166 | outer_context_id: String.t() 167 | } 168 | defstruct [ 169 | :graph_id, 170 | :graph_name, 171 | :instrumented_ops, 172 | :original_graph_def, 173 | :instrumented_graph_def, 174 | :outer_context_id 175 | ] 176 | 177 | field(:graph_id, 1, type: :string) 178 | field(:graph_name, 2, type: :string) 179 | field(:instrumented_ops, 3, repeated: true, type: :string) 180 | field(:original_graph_def, 4, type: :bytes) 181 | field(:instrumented_graph_def, 5, type: :bytes) 182 | field(:outer_context_id, 6, type: :string) 183 | end 184 | 185 | defmodule Tensorflow.DebuggedDevice do 186 | @moduledoc false 187 | use Protobuf, syntax: :proto3 188 | 189 | @type t :: %__MODULE__{ 190 | device_name: String.t(), 191 | device_id: integer 192 | } 193 | defstruct [:device_name, :device_id] 194 | 195 | field(:device_name, 1, type: :string) 196 | field(:device_id, 2, type: :int32) 197 | end 198 | 199 | defmodule Tensorflow.Execution do 200 | @moduledoc false 201 | use Protobuf, syntax: :proto3 202 | 203 | @type t :: %__MODULE__{ 204 | op_type: String.t(), 205 | num_outputs: integer, 206 | graph_id: String.t(), 207 | input_tensor_ids: [integer], 208 | output_tensor_ids: [integer], 209 | tensor_debug_mode: Tensorflow.TensorDebugMode.t(), 210 | tensor_protos: [Tensorflow.TensorProto.t()], 211 | code_location: Tensorflow.CodeLocation.t() | nil, 212 | output_tensor_device_ids: [integer] 213 | } 214 | defstruct [ 215 | :op_type, 216 | :num_outputs, 217 | :graph_id, 218 | :input_tensor_ids, 219 | :output_tensor_ids, 220 | :tensor_debug_mode, 221 | :tensor_protos, 222 | :code_location, 223 | :output_tensor_device_ids 224 | ] 225 | 226 | field(:op_type, 1, type: :string) 227 | field(:num_outputs, 2, type: :int32) 228 | field(:graph_id, 3, type: :string) 229 | field(:input_tensor_ids, 4, repeated: true, type: :int64) 230 | field(:output_tensor_ids, 5, repeated: true, type: :int64) 231 | field(:tensor_debug_mode, 6, type: Tensorflow.TensorDebugMode, enum: true) 232 | field(:tensor_protos, 7, repeated: true, type: Tensorflow.TensorProto) 233 | field(:code_location, 8, type: Tensorflow.CodeLocation) 234 | field(:output_tensor_device_ids, 9, repeated: true, type: :int32) 235 | end 236 | 237 | defmodule Tensorflow.GraphExecutionTrace do 238 | @moduledoc false 239 | use Protobuf, syntax: :proto3 240 | 241 | @type t :: %__MODULE__{ 242 | tfdbg_context_id: String.t(), 243 | op_name: String.t(), 244 | output_slot: integer, 245 | tensor_debug_mode: Tensorflow.TensorDebugMode.t(), 246 | tensor_proto: Tensorflow.TensorProto.t() | nil, 247 | device_name: String.t() 248 | } 249 | defstruct [ 250 | :tfdbg_context_id, 251 | :op_name, 252 | :output_slot, 253 | :tensor_debug_mode, 254 | :tensor_proto, 255 | :device_name 256 | ] 257 | 258 | field(:tfdbg_context_id, 1, type: :string) 259 | field(:op_name, 2, type: :string) 260 | field(:output_slot, 3, type: :int32) 261 | field(:tensor_debug_mode, 4, type: Tensorflow.TensorDebugMode, enum: true) 262 | field(:tensor_proto, 5, type: Tensorflow.TensorProto) 263 | field(:device_name, 6, type: :string) 264 | end 265 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/device_filters.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.TaskDeviceFilters do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | device_filters: [String.t()] 7 | } 8 | defstruct [:device_filters] 9 | 10 | field(:device_filters, 1, repeated: true, type: :string) 11 | end 12 | 13 | defmodule Tensorflow.JobDeviceFilters.TasksEntry do 14 | @moduledoc false 15 | use Protobuf, map: true, syntax: :proto3 16 | 17 | @type t :: %__MODULE__{ 18 | key: integer, 19 | value: Tensorflow.TaskDeviceFilters.t() | nil 20 | } 21 | defstruct [:key, :value] 22 | 23 | field(:key, 1, type: :int32) 24 | field(:value, 2, type: Tensorflow.TaskDeviceFilters) 25 | end 26 | 27 | defmodule Tensorflow.JobDeviceFilters do 28 | @moduledoc false 29 | use Protobuf, syntax: :proto3 30 | 31 | @type t :: %__MODULE__{ 32 | name: String.t(), 33 | tasks: %{integer => Tensorflow.TaskDeviceFilters.t() | nil} 34 | } 35 | defstruct [:name, :tasks] 36 | 37 | field(:name, 1, type: :string) 38 | 39 | field(:tasks, 2, 40 | repeated: true, 41 | type: Tensorflow.JobDeviceFilters.TasksEntry, 42 | map: true 43 | ) 44 | end 45 | 46 | defmodule Tensorflow.ClusterDeviceFilters do 47 | @moduledoc false 48 | use Protobuf, syntax: :proto3 49 | 50 | @type t :: %__MODULE__{ 51 | jobs: [Tensorflow.JobDeviceFilters.t()] 52 | } 53 | defstruct [:jobs] 54 | 55 | field(:jobs, 1, repeated: true, type: Tensorflow.JobDeviceFilters) 56 | end 57 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/device_properties.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.DeviceProperties.EnvironmentEntry do 2 | @moduledoc false 3 | use Protobuf, map: true, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | key: String.t(), 7 | value: String.t() 8 | } 9 | defstruct [:key, :value] 10 | 11 | field(:key, 1, type: :string) 12 | field(:value, 2, type: :string) 13 | end 14 | 15 | defmodule Tensorflow.DeviceProperties do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | type: String.t(), 21 | vendor: String.t(), 22 | model: String.t(), 23 | frequency: integer, 24 | num_cores: integer, 25 | environment: %{String.t() => String.t()}, 26 | num_registers: integer, 27 | l1_cache_size: integer, 28 | l2_cache_size: integer, 29 | l3_cache_size: integer, 30 | shared_memory_size_per_multiprocessor: integer, 31 | memory_size: integer, 32 | bandwidth: integer 33 | } 34 | defstruct [ 35 | :type, 36 | :vendor, 37 | :model, 38 | :frequency, 39 | :num_cores, 40 | :environment, 41 | :num_registers, 42 | :l1_cache_size, 43 | :l2_cache_size, 44 | :l3_cache_size, 45 | :shared_memory_size_per_multiprocessor, 46 | :memory_size, 47 | :bandwidth 48 | ] 49 | 50 | field(:type, 1, type: :string) 51 | field(:vendor, 2, type: :string) 52 | field(:model, 3, type: :string) 53 | field(:frequency, 4, type: :int64) 54 | field(:num_cores, 5, type: :int64) 55 | 56 | field(:environment, 6, 57 | repeated: true, 58 | type: Tensorflow.DeviceProperties.EnvironmentEntry, 59 | map: true 60 | ) 61 | 62 | field(:num_registers, 7, type: :int64) 63 | field(:l1_cache_size, 8, type: :int64) 64 | field(:l2_cache_size, 9, type: :int64) 65 | field(:l3_cache_size, 10, type: :int64) 66 | field(:shared_memory_size_per_multiprocessor, 11, type: :int64) 67 | field(:memory_size, 12, type: :int64) 68 | field(:bandwidth, 13, type: :int64) 69 | end 70 | 71 | defmodule Tensorflow.NamedDevice do 72 | @moduledoc false 73 | use Protobuf, syntax: :proto3 74 | 75 | @type t :: %__MODULE__{ 76 | name: String.t(), 77 | properties: Tensorflow.DeviceProperties.t() | nil 78 | } 79 | defstruct [:name, :properties] 80 | 81 | field(:name, 1, type: :string) 82 | field(:properties, 2, type: Tensorflow.DeviceProperties) 83 | end 84 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/error_codes.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.Error.Code do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: 6 | integer 7 | | :OK 8 | | :CANCELLED 9 | | :UNKNOWN 10 | | :INVALID_ARGUMENT 11 | | :DEADLINE_EXCEEDED 12 | | :NOT_FOUND 13 | | :ALREADY_EXISTS 14 | | :PERMISSION_DENIED 15 | | :UNAUTHENTICATED 16 | | :RESOURCE_EXHAUSTED 17 | | :FAILED_PRECONDITION 18 | | :ABORTED 19 | | :OUT_OF_RANGE 20 | | :UNIMPLEMENTED 21 | | :INTERNAL 22 | | :UNAVAILABLE 23 | | :DATA_LOSS 24 | | :DO_NOT_USE_RESERVED_FOR_FUTURE_EXPANSION_USE_DEFAULT_IN_SWITCH_INSTEAD_ 25 | 26 | field(:OK, 0) 27 | field(:CANCELLED, 1) 28 | field(:UNKNOWN, 2) 29 | field(:INVALID_ARGUMENT, 3) 30 | field(:DEADLINE_EXCEEDED, 4) 31 | field(:NOT_FOUND, 5) 32 | field(:ALREADY_EXISTS, 6) 33 | field(:PERMISSION_DENIED, 7) 34 | field(:UNAUTHENTICATED, 16) 35 | field(:RESOURCE_EXHAUSTED, 8) 36 | field(:FAILED_PRECONDITION, 9) 37 | field(:ABORTED, 10) 38 | field(:OUT_OF_RANGE, 11) 39 | field(:UNIMPLEMENTED, 12) 40 | field(:INTERNAL, 13) 41 | field(:UNAVAILABLE, 14) 42 | field(:DATA_LOSS, 15) 43 | 44 | field( 45 | :DO_NOT_USE_RESERVED_FOR_FUTURE_EXPANSION_USE_DEFAULT_IN_SWITCH_INSTEAD_, 46 | 20 47 | ) 48 | end 49 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/graph_debug_info.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.GraphDebugInfo.FileLineCol do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | file_index: integer, 7 | line: integer, 8 | col: integer, 9 | func: String.t(), 10 | code: String.t() 11 | } 12 | defstruct [:file_index, :line, :col, :func, :code] 13 | 14 | field(:file_index, 1, type: :int32) 15 | field(:line, 2, type: :int32) 16 | field(:col, 3, type: :int32) 17 | field(:func, 4, type: :string) 18 | field(:code, 5, type: :string) 19 | end 20 | 21 | defmodule Tensorflow.GraphDebugInfo.StackTrace do 22 | @moduledoc false 23 | use Protobuf, syntax: :proto3 24 | 25 | @type t :: %__MODULE__{ 26 | file_line_cols: [Tensorflow.GraphDebugInfo.FileLineCol.t()] 27 | } 28 | defstruct [:file_line_cols] 29 | 30 | field(:file_line_cols, 1, 31 | repeated: true, 32 | type: Tensorflow.GraphDebugInfo.FileLineCol 33 | ) 34 | end 35 | 36 | defmodule Tensorflow.GraphDebugInfo.TracesEntry do 37 | @moduledoc false 38 | use Protobuf, map: true, syntax: :proto3 39 | 40 | @type t :: %__MODULE__{ 41 | key: String.t(), 42 | value: Tensorflow.GraphDebugInfo.StackTrace.t() | nil 43 | } 44 | defstruct [:key, :value] 45 | 46 | field(:key, 1, type: :string) 47 | field(:value, 2, type: Tensorflow.GraphDebugInfo.StackTrace) 48 | end 49 | 50 | defmodule Tensorflow.GraphDebugInfo do 51 | @moduledoc false 52 | use Protobuf, syntax: :proto3 53 | 54 | @type t :: %__MODULE__{ 55 | files: [String.t()], 56 | traces: %{ 57 | String.t() => Tensorflow.GraphDebugInfo.StackTrace.t() | nil 58 | } 59 | } 60 | defstruct [:files, :traces] 61 | 62 | field(:files, 1, repeated: true, type: :string) 63 | 64 | field(:traces, 2, 65 | repeated: true, 66 | type: Tensorflow.GraphDebugInfo.TracesEntry, 67 | map: true 68 | ) 69 | end 70 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/master.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.CreateSessionRequest do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | graph_def: Tensorflow.GraphDef.t() | nil, 7 | config: Tensorflow.ConfigProto.t() | nil, 8 | target: String.t() 9 | } 10 | defstruct [:graph_def, :config, :target] 11 | 12 | field(:graph_def, 1, type: Tensorflow.GraphDef) 13 | field(:config, 2, type: Tensorflow.ConfigProto) 14 | field(:target, 3, type: :string) 15 | end 16 | 17 | defmodule Tensorflow.CreateSessionResponse do 18 | @moduledoc false 19 | use Protobuf, syntax: :proto3 20 | 21 | @type t :: %__MODULE__{ 22 | session_handle: String.t(), 23 | graph_version: integer 24 | } 25 | defstruct [:session_handle, :graph_version] 26 | 27 | field(:session_handle, 1, type: :string) 28 | field(:graph_version, 2, type: :int64) 29 | end 30 | 31 | defmodule Tensorflow.ExtendSessionRequest do 32 | @moduledoc false 33 | use Protobuf, syntax: :proto3 34 | 35 | @type t :: %__MODULE__{ 36 | session_handle: String.t(), 37 | graph_def: Tensorflow.GraphDef.t() | nil, 38 | current_graph_version: integer 39 | } 40 | defstruct [:session_handle, :graph_def, :current_graph_version] 41 | 42 | field(:session_handle, 1, type: :string) 43 | field(:graph_def, 2, type: Tensorflow.GraphDef) 44 | field(:current_graph_version, 3, type: :int64) 45 | end 46 | 47 | defmodule Tensorflow.ExtendSessionResponse do 48 | @moduledoc false 49 | use Protobuf, syntax: :proto3 50 | 51 | @type t :: %__MODULE__{ 52 | new_graph_version: integer 53 | } 54 | defstruct [:new_graph_version] 55 | 56 | field(:new_graph_version, 4, type: :int64) 57 | end 58 | 59 | defmodule Tensorflow.RunStepRequest do 60 | @moduledoc false 61 | use Protobuf, syntax: :proto3 62 | 63 | @type t :: %__MODULE__{ 64 | session_handle: String.t(), 65 | feed: [Tensorflow.NamedTensorProto.t()], 66 | fetch: [String.t()], 67 | target: [String.t()], 68 | options: Tensorflow.RunOptions.t() | nil, 69 | partial_run_handle: String.t(), 70 | store_errors_in_response_body: boolean, 71 | request_id: integer 72 | } 73 | defstruct [ 74 | :session_handle, 75 | :feed, 76 | :fetch, 77 | :target, 78 | :options, 79 | :partial_run_handle, 80 | :store_errors_in_response_body, 81 | :request_id 82 | ] 83 | 84 | field(:session_handle, 1, type: :string) 85 | field(:feed, 2, repeated: true, type: Tensorflow.NamedTensorProto) 86 | field(:fetch, 3, repeated: true, type: :string) 87 | field(:target, 4, repeated: true, type: :string) 88 | field(:options, 5, type: Tensorflow.RunOptions) 89 | field(:partial_run_handle, 6, type: :string) 90 | field(:store_errors_in_response_body, 7, type: :bool) 91 | field(:request_id, 8, type: :int64) 92 | end 93 | 94 | defmodule Tensorflow.RunStepResponse do 95 | @moduledoc false 96 | use Protobuf, syntax: :proto3 97 | 98 | @type t :: %__MODULE__{ 99 | tensor: [Tensorflow.NamedTensorProto.t()], 100 | metadata: Tensorflow.RunMetadata.t() | nil, 101 | status_code: Tensorflow.Error.Code.t(), 102 | status_error_message: String.t() 103 | } 104 | defstruct [:tensor, :metadata, :status_code, :status_error_message] 105 | 106 | field(:tensor, 1, repeated: true, type: Tensorflow.NamedTensorProto) 107 | field(:metadata, 2, type: Tensorflow.RunMetadata) 108 | field(:status_code, 3, type: Tensorflow.Error.Code, enum: true) 109 | field(:status_error_message, 4, type: :string) 110 | end 111 | 112 | defmodule Tensorflow.PartialRunSetupRequest do 113 | @moduledoc false 114 | use Protobuf, syntax: :proto3 115 | 116 | @type t :: %__MODULE__{ 117 | session_handle: String.t(), 118 | feed: [String.t()], 119 | fetch: [String.t()], 120 | target: [String.t()], 121 | request_id: integer 122 | } 123 | defstruct [:session_handle, :feed, :fetch, :target, :request_id] 124 | 125 | field(:session_handle, 1, type: :string) 126 | field(:feed, 2, repeated: true, type: :string) 127 | field(:fetch, 3, repeated: true, type: :string) 128 | field(:target, 4, repeated: true, type: :string) 129 | field(:request_id, 5, type: :int64) 130 | end 131 | 132 | defmodule Tensorflow.PartialRunSetupResponse do 133 | @moduledoc false 134 | use Protobuf, syntax: :proto3 135 | 136 | @type t :: %__MODULE__{ 137 | partial_run_handle: String.t() 138 | } 139 | defstruct [:partial_run_handle] 140 | 141 | field(:partial_run_handle, 1, type: :string) 142 | end 143 | 144 | defmodule Tensorflow.CloseSessionRequest do 145 | @moduledoc false 146 | use Protobuf, syntax: :proto3 147 | 148 | @type t :: %__MODULE__{ 149 | session_handle: String.t() 150 | } 151 | defstruct [:session_handle] 152 | 153 | field(:session_handle, 1, type: :string) 154 | end 155 | 156 | defmodule Tensorflow.CloseSessionResponse do 157 | @moduledoc false 158 | use Protobuf, syntax: :proto3 159 | 160 | @type t :: %__MODULE__{} 161 | defstruct [] 162 | end 163 | 164 | defmodule Tensorflow.ResetRequest do 165 | @moduledoc false 166 | use Protobuf, syntax: :proto3 167 | 168 | @type t :: %__MODULE__{ 169 | container: [String.t()], 170 | device_filters: [String.t()] 171 | } 172 | defstruct [:container, :device_filters] 173 | 174 | field(:container, 1, repeated: true, type: :string) 175 | field(:device_filters, 2, repeated: true, type: :string) 176 | end 177 | 178 | defmodule Tensorflow.ResetResponse do 179 | @moduledoc false 180 | use Protobuf, syntax: :proto3 181 | 182 | @type t :: %__MODULE__{} 183 | defstruct [] 184 | end 185 | 186 | defmodule Tensorflow.ListDevicesRequest do 187 | @moduledoc false 188 | use Protobuf, syntax: :proto3 189 | 190 | @type t :: %__MODULE__{ 191 | session_handle: String.t() 192 | } 193 | defstruct [:session_handle] 194 | 195 | field(:session_handle, 1, type: :string) 196 | end 197 | 198 | defmodule Tensorflow.ListDevicesResponse do 199 | @moduledoc false 200 | use Protobuf, syntax: :proto3 201 | 202 | @type t :: %__MODULE__{ 203 | local_device: [Tensorflow.DeviceAttributes.t()], 204 | remote_device: [Tensorflow.DeviceAttributes.t()] 205 | } 206 | defstruct [:local_device, :remote_device] 207 | 208 | field(:local_device, 1, repeated: true, type: Tensorflow.DeviceAttributes) 209 | field(:remote_device, 2, repeated: true, type: Tensorflow.DeviceAttributes) 210 | end 211 | 212 | defmodule Tensorflow.MakeCallableRequest do 213 | @moduledoc false 214 | use Protobuf, syntax: :proto3 215 | 216 | @type t :: %__MODULE__{ 217 | session_handle: String.t(), 218 | options: Tensorflow.CallableOptions.t() | nil, 219 | request_id: integer 220 | } 221 | defstruct [:session_handle, :options, :request_id] 222 | 223 | field(:session_handle, 1, type: :string) 224 | field(:options, 2, type: Tensorflow.CallableOptions) 225 | field(:request_id, 3, type: :int64) 226 | end 227 | 228 | defmodule Tensorflow.MakeCallableResponse do 229 | @moduledoc false 230 | use Protobuf, syntax: :proto3 231 | 232 | @type t :: %__MODULE__{ 233 | handle: integer 234 | } 235 | defstruct [:handle] 236 | 237 | field(:handle, 1, type: :int64) 238 | end 239 | 240 | defmodule Tensorflow.RunCallableRequest do 241 | @moduledoc false 242 | use Protobuf, syntax: :proto3 243 | 244 | @type t :: %__MODULE__{ 245 | session_handle: String.t(), 246 | handle: integer, 247 | feed: [Tensorflow.TensorProto.t()], 248 | request_id: integer 249 | } 250 | defstruct [:session_handle, :handle, :feed, :request_id] 251 | 252 | field(:session_handle, 1, type: :string) 253 | field(:handle, 2, type: :int64) 254 | field(:feed, 3, repeated: true, type: Tensorflow.TensorProto) 255 | field(:request_id, 4, type: :int64) 256 | end 257 | 258 | defmodule Tensorflow.RunCallableResponse do 259 | @moduledoc false 260 | use Protobuf, syntax: :proto3 261 | 262 | @type t :: %__MODULE__{ 263 | fetch: [Tensorflow.TensorProto.t()], 264 | metadata: Tensorflow.RunMetadata.t() | nil 265 | } 266 | defstruct [:fetch, :metadata] 267 | 268 | field(:fetch, 1, repeated: true, type: Tensorflow.TensorProto) 269 | field(:metadata, 2, type: Tensorflow.RunMetadata) 270 | end 271 | 272 | defmodule Tensorflow.ReleaseCallableRequest do 273 | @moduledoc false 274 | use Protobuf, syntax: :proto3 275 | 276 | @type t :: %__MODULE__{ 277 | session_handle: String.t(), 278 | handle: integer 279 | } 280 | defstruct [:session_handle, :handle] 281 | 282 | field(:session_handle, 1, type: :string) 283 | field(:handle, 2, type: :int64) 284 | end 285 | 286 | defmodule Tensorflow.ReleaseCallableResponse do 287 | @moduledoc false 288 | use Protobuf, syntax: :proto3 289 | 290 | @type t :: %__MODULE__{} 291 | defstruct [] 292 | end 293 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/master_service.pb.ex: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/named_tensor.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.NamedTensorProto do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | name: String.t(), 7 | tensor: Tensorflow.TensorProto.t() | nil 8 | } 9 | defstruct [:name, :tensor] 10 | 11 | field(:name, 1, type: :string) 12 | field(:tensor, 2, type: Tensorflow.TensorProto) 13 | end 14 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/queue_runner.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.QueueRunnerDef do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | queue_name: String.t(), 7 | enqueue_op_name: [String.t()], 8 | close_op_name: String.t(), 9 | cancel_op_name: String.t(), 10 | queue_closed_exception_types: [[Tensorflow.Error.Code.t()]] 11 | } 12 | defstruct [ 13 | :queue_name, 14 | :enqueue_op_name, 15 | :close_op_name, 16 | :cancel_op_name, 17 | :queue_closed_exception_types 18 | ] 19 | 20 | field(:queue_name, 1, type: :string) 21 | field(:enqueue_op_name, 2, repeated: true, type: :string) 22 | field(:close_op_name, 3, type: :string) 23 | field(:cancel_op_name, 4, type: :string) 24 | 25 | field(:queue_closed_exception_types, 5, 26 | repeated: true, 27 | type: Tensorflow.Error.Code, 28 | enum: true 29 | ) 30 | end 31 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/remote_tensor_handle.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.Eager.ResourceDtypeAndShape do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | dtype: Tensorflow.DataType.t(), 7 | shape: Tensorflow.TensorShapeProto.t() | nil 8 | } 9 | defstruct [:dtype, :shape] 10 | 11 | field(:dtype, 1, type: Tensorflow.DataType, enum: true) 12 | field(:shape, 2, type: Tensorflow.TensorShapeProto) 13 | end 14 | 15 | defmodule Tensorflow.Eager.RemoteTensorHandle do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | op_id: integer, 21 | output_num: integer, 22 | device: String.t(), 23 | op_device: String.t(), 24 | dtype: Tensorflow.DataType.t(), 25 | resource_dtypes_and_shapes: [ 26 | Tensorflow.Eager.ResourceDtypeAndShape.t() 27 | ] 28 | } 29 | defstruct [ 30 | :op_id, 31 | :output_num, 32 | :device, 33 | :op_device, 34 | :dtype, 35 | :resource_dtypes_and_shapes 36 | ] 37 | 38 | field(:op_id, 1, type: :int64) 39 | field(:output_num, 2, type: :int32) 40 | field(:device, 3, type: :string) 41 | field(:op_device, 4, type: :string) 42 | field(:dtype, 5, type: Tensorflow.DataType, enum: true) 43 | 44 | field(:resource_dtypes_and_shapes, 6, 45 | repeated: true, 46 | type: Tensorflow.Eager.ResourceDtypeAndShape 47 | ) 48 | end 49 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/replay_log.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.NewReplaySession do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | devices: Tensorflow.ListDevicesResponse.t() | nil, 7 | session_handle: String.t() 8 | } 9 | defstruct [:devices, :session_handle] 10 | 11 | field(:devices, 1, type: Tensorflow.ListDevicesResponse) 12 | field(:session_handle, 2, type: :string) 13 | end 14 | 15 | defmodule Tensorflow.ReplayOp do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | op: {atom, any}, 21 | response: {atom, any}, 22 | start_time_us: float | :infinity | :negative_infinity | :nan, 23 | end_time_us: float | :infinity | :negative_infinity | :nan 24 | } 25 | defstruct [:op, :response, :start_time_us, :end_time_us] 26 | 27 | oneof(:op, 0) 28 | oneof(:response, 1) 29 | field(:start_time_us, 31, type: :double) 30 | field(:end_time_us, 32, type: :double) 31 | field(:create_session, 1, type: Tensorflow.CreateSessionRequest, oneof: 0) 32 | field(:extend_session, 2, type: Tensorflow.ExtendSessionRequest, oneof: 0) 33 | 34 | field(:partial_run_setup, 3, 35 | type: Tensorflow.PartialRunSetupRequest, 36 | oneof: 0 37 | ) 38 | 39 | field(:run_step, 4, type: Tensorflow.RunStepRequest, oneof: 0) 40 | field(:close_session, 5, type: Tensorflow.CloseSessionRequest, oneof: 0) 41 | field(:list_devices, 6, type: Tensorflow.ListDevicesRequest, oneof: 0) 42 | field(:reset_request, 7, type: Tensorflow.ResetRequest, oneof: 0) 43 | field(:make_callable, 8, type: Tensorflow.MakeCallableRequest, oneof: 0) 44 | field(:run_callable, 9, type: Tensorflow.RunCallableRequest, oneof: 0) 45 | 46 | field(:release_callable, 10, 47 | type: Tensorflow.ReleaseCallableRequest, 48 | oneof: 0 49 | ) 50 | 51 | field(:new_replay_session, 11, type: Tensorflow.NewReplaySession, oneof: 0) 52 | 53 | field(:create_session_response, 21, 54 | type: Tensorflow.CreateSessionResponse, 55 | oneof: 1 56 | ) 57 | 58 | field(:extend_session_response, 22, 59 | type: Tensorflow.ExtendSessionResponse, 60 | oneof: 1 61 | ) 62 | 63 | field(:partial_run_setup_response, 23, 64 | type: Tensorflow.PartialRunSetupResponse, 65 | oneof: 1 66 | ) 67 | 68 | field(:run_step_response, 24, type: Tensorflow.RunStepResponse, oneof: 1) 69 | 70 | field(:close_session_response, 25, 71 | type: Tensorflow.CloseSessionResponse, 72 | oneof: 1 73 | ) 74 | 75 | field(:list_devices_response, 26, 76 | type: Tensorflow.ListDevicesResponse, 77 | oneof: 1 78 | ) 79 | 80 | field(:reset_request_response, 27, type: Tensorflow.ResetResponse, oneof: 1) 81 | 82 | field(:make_callable_response, 28, 83 | type: Tensorflow.MakeCallableResponse, 84 | oneof: 1 85 | ) 86 | 87 | field(:run_callable_response, 29, 88 | type: Tensorflow.RunCallableResponse, 89 | oneof: 1 90 | ) 91 | 92 | field(:release_callable_response, 30, 93 | type: Tensorflow.ReleaseCallableResponse, 94 | oneof: 1 95 | ) 96 | end 97 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/saved_model.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.SavedModel do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | saved_model_schema_version: integer, 7 | meta_graphs: [Tensorflow.MetaGraphDef.t()] 8 | } 9 | defstruct [:saved_model_schema_version, :meta_graphs] 10 | 11 | field(:saved_model_schema_version, 1, type: :int64) 12 | field(:meta_graphs, 2, repeated: true, type: Tensorflow.MetaGraphDef) 13 | end 14 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/saved_object_graph.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.FunctionSpec.ExperimentalCompile do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: integer | :DEFAULT | :ON | :OFF 6 | 7 | field(:DEFAULT, 0) 8 | field(:ON, 1) 9 | field(:OFF, 2) 10 | end 11 | 12 | defmodule Tensorflow.SavedObjectGraph.ConcreteFunctionsEntry do 13 | @moduledoc false 14 | use Protobuf, map: true, syntax: :proto3 15 | 16 | @type t :: %__MODULE__{ 17 | key: String.t(), 18 | value: Tensorflow.SavedConcreteFunction.t() | nil 19 | } 20 | defstruct [:key, :value] 21 | 22 | field(:key, 1, type: :string) 23 | field(:value, 2, type: Tensorflow.SavedConcreteFunction) 24 | end 25 | 26 | defmodule Tensorflow.SavedObjectGraph do 27 | @moduledoc false 28 | use Protobuf, syntax: :proto3 29 | 30 | @type t :: %__MODULE__{ 31 | nodes: [Tensorflow.SavedObject.t()], 32 | concrete_functions: %{ 33 | String.t() => Tensorflow.SavedConcreteFunction.t() | nil 34 | } 35 | } 36 | defstruct [:nodes, :concrete_functions] 37 | 38 | field(:nodes, 1, repeated: true, type: Tensorflow.SavedObject) 39 | 40 | field(:concrete_functions, 2, 41 | repeated: true, 42 | type: Tensorflow.SavedObjectGraph.ConcreteFunctionsEntry, 43 | map: true 44 | ) 45 | end 46 | 47 | defmodule Tensorflow.SavedObject.SaveableObjectsEntry do 48 | @moduledoc false 49 | use Protobuf, map: true, syntax: :proto3 50 | 51 | @type t :: %__MODULE__{ 52 | key: String.t(), 53 | value: Tensorflow.SaveableObject.t() | nil 54 | } 55 | defstruct [:key, :value] 56 | 57 | field(:key, 1, type: :string) 58 | field(:value, 2, type: Tensorflow.SaveableObject) 59 | end 60 | 61 | defmodule Tensorflow.SavedObject do 62 | @moduledoc false 63 | use Protobuf, syntax: :proto3 64 | 65 | @type t :: %__MODULE__{ 66 | kind: {atom, any}, 67 | children: [ 68 | Tensorflow.TrackableObjectGraph.TrackableObject.ObjectReference.t() 69 | ], 70 | slot_variables: [ 71 | Tensorflow.TrackableObjectGraph.TrackableObject.SlotVariableReference.t() 72 | ], 73 | saveable_objects: %{ 74 | String.t() => Tensorflow.SaveableObject.t() | nil 75 | } 76 | } 77 | defstruct [:kind, :children, :slot_variables, :saveable_objects] 78 | 79 | oneof(:kind, 0) 80 | 81 | field(:children, 1, 82 | repeated: true, 83 | type: Tensorflow.TrackableObjectGraph.TrackableObject.ObjectReference 84 | ) 85 | 86 | field(:slot_variables, 3, 87 | repeated: true, 88 | type: 89 | Tensorflow.TrackableObjectGraph.TrackableObject.SlotVariableReference 90 | ) 91 | 92 | field(:user_object, 4, type: Tensorflow.SavedUserObject, oneof: 0) 93 | field(:asset, 5, type: Tensorflow.SavedAsset, oneof: 0) 94 | field(:function, 6, type: Tensorflow.SavedFunction, oneof: 0) 95 | field(:variable, 7, type: Tensorflow.SavedVariable, oneof: 0) 96 | 97 | field(:bare_concrete_function, 8, 98 | type: Tensorflow.SavedBareConcreteFunction, 99 | oneof: 0 100 | ) 101 | 102 | field(:constant, 9, type: Tensorflow.SavedConstant, oneof: 0) 103 | field(:resource, 10, type: Tensorflow.SavedResource, oneof: 0) 104 | 105 | field(:saveable_objects, 11, 106 | repeated: true, 107 | type: Tensorflow.SavedObject.SaveableObjectsEntry, 108 | map: true 109 | ) 110 | end 111 | 112 | defmodule Tensorflow.SavedUserObject do 113 | @moduledoc false 114 | use Protobuf, syntax: :proto3 115 | 116 | @type t :: %__MODULE__{ 117 | identifier: String.t(), 118 | version: Tensorflow.VersionDef.t() | nil, 119 | metadata: String.t() 120 | } 121 | defstruct [:identifier, :version, :metadata] 122 | 123 | field(:identifier, 1, type: :string) 124 | field(:version, 2, type: Tensorflow.VersionDef) 125 | field(:metadata, 3, type: :string) 126 | end 127 | 128 | defmodule Tensorflow.SavedAsset do 129 | @moduledoc false 130 | use Protobuf, syntax: :proto3 131 | 132 | @type t :: %__MODULE__{ 133 | asset_file_def_index: integer 134 | } 135 | defstruct [:asset_file_def_index] 136 | 137 | field(:asset_file_def_index, 1, type: :int32) 138 | end 139 | 140 | defmodule Tensorflow.SavedFunction do 141 | @moduledoc false 142 | use Protobuf, syntax: :proto3 143 | 144 | @type t :: %__MODULE__{ 145 | concrete_functions: [String.t()], 146 | function_spec: Tensorflow.FunctionSpec.t() | nil 147 | } 148 | defstruct [:concrete_functions, :function_spec] 149 | 150 | field(:concrete_functions, 1, repeated: true, type: :string) 151 | field(:function_spec, 2, type: Tensorflow.FunctionSpec) 152 | end 153 | 154 | defmodule Tensorflow.SavedConcreteFunction do 155 | @moduledoc false 156 | use Protobuf, syntax: :proto3 157 | 158 | @type t :: %__MODULE__{ 159 | bound_inputs: [integer], 160 | canonicalized_input_signature: Tensorflow.StructuredValue.t() | nil, 161 | output_signature: Tensorflow.StructuredValue.t() | nil 162 | } 163 | defstruct [:bound_inputs, :canonicalized_input_signature, :output_signature] 164 | 165 | field(:bound_inputs, 2, repeated: true, type: :int32) 166 | field(:canonicalized_input_signature, 3, type: Tensorflow.StructuredValue) 167 | field(:output_signature, 4, type: Tensorflow.StructuredValue) 168 | end 169 | 170 | defmodule Tensorflow.SavedBareConcreteFunction do 171 | @moduledoc false 172 | use Protobuf, syntax: :proto3 173 | 174 | @type t :: %__MODULE__{ 175 | concrete_function_name: String.t(), 176 | argument_keywords: [String.t()], 177 | allowed_positional_arguments: integer 178 | } 179 | defstruct [ 180 | :concrete_function_name, 181 | :argument_keywords, 182 | :allowed_positional_arguments 183 | ] 184 | 185 | field(:concrete_function_name, 1, type: :string) 186 | field(:argument_keywords, 2, repeated: true, type: :string) 187 | field(:allowed_positional_arguments, 3, type: :int64) 188 | end 189 | 190 | defmodule Tensorflow.SavedConstant do 191 | @moduledoc false 192 | use Protobuf, syntax: :proto3 193 | 194 | @type t :: %__MODULE__{ 195 | operation: String.t() 196 | } 197 | defstruct [:operation] 198 | 199 | field(:operation, 1, type: :string) 200 | end 201 | 202 | defmodule Tensorflow.SavedVariable do 203 | @moduledoc false 204 | use Protobuf, syntax: :proto3 205 | 206 | @type t :: %__MODULE__{ 207 | dtype: Tensorflow.DataType.t(), 208 | shape: Tensorflow.TensorShapeProto.t() | nil, 209 | trainable: boolean, 210 | synchronization: Tensorflow.VariableSynchronization.t(), 211 | aggregation: Tensorflow.VariableAggregation.t(), 212 | name: String.t(), 213 | device: String.t(), 214 | experimental_distributed_variable_components: [ 215 | Tensorflow.SavedVariable.t() 216 | ] 217 | } 218 | defstruct [ 219 | :dtype, 220 | :shape, 221 | :trainable, 222 | :synchronization, 223 | :aggregation, 224 | :name, 225 | :device, 226 | :experimental_distributed_variable_components 227 | ] 228 | 229 | field(:dtype, 1, type: Tensorflow.DataType, enum: true) 230 | field(:shape, 2, type: Tensorflow.TensorShapeProto) 231 | field(:trainable, 3, type: :bool) 232 | 233 | field(:synchronization, 4, 234 | type: Tensorflow.VariableSynchronization, 235 | enum: true 236 | ) 237 | 238 | field(:aggregation, 5, type: Tensorflow.VariableAggregation, enum: true) 239 | field(:name, 6, type: :string) 240 | field(:device, 7, type: :string) 241 | 242 | field(:experimental_distributed_variable_components, 8, 243 | repeated: true, 244 | type: Tensorflow.SavedVariable 245 | ) 246 | end 247 | 248 | defmodule Tensorflow.FunctionSpec do 249 | @moduledoc false 250 | use Protobuf, syntax: :proto3 251 | 252 | @type t :: %__MODULE__{ 253 | fullargspec: Tensorflow.StructuredValue.t() | nil, 254 | is_method: boolean, 255 | input_signature: Tensorflow.StructuredValue.t() | nil, 256 | experimental_compile: 257 | Tensorflow.FunctionSpec.ExperimentalCompile.t() 258 | } 259 | defstruct [ 260 | :fullargspec, 261 | :is_method, 262 | :input_signature, 263 | :experimental_compile 264 | ] 265 | 266 | field(:fullargspec, 1, type: Tensorflow.StructuredValue) 267 | field(:is_method, 2, type: :bool) 268 | field(:input_signature, 5, type: Tensorflow.StructuredValue) 269 | 270 | field(:experimental_compile, 6, 271 | type: Tensorflow.FunctionSpec.ExperimentalCompile, 272 | enum: true 273 | ) 274 | end 275 | 276 | defmodule Tensorflow.SavedResource do 277 | @moduledoc false 278 | use Protobuf, syntax: :proto3 279 | 280 | @type t :: %__MODULE__{ 281 | device: String.t() 282 | } 283 | defstruct [:device] 284 | 285 | field(:device, 1, type: :string) 286 | end 287 | 288 | defmodule Tensorflow.SaveableObject do 289 | @moduledoc false 290 | use Protobuf, syntax: :proto3 291 | 292 | @type t :: %__MODULE__{ 293 | save_function: integer, 294 | restore_function: integer 295 | } 296 | defstruct [:save_function, :restore_function] 297 | 298 | field(:save_function, 2, type: :int32) 299 | field(:restore_function, 3, type: :int32) 300 | end 301 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/saver.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.SaverDef.CheckpointFormatVersion do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: integer | :LEGACY | :V1 | :V2 6 | 7 | field(:LEGACY, 0) 8 | field(:V1, 1) 9 | field(:V2, 2) 10 | end 11 | 12 | defmodule Tensorflow.SaverDef do 13 | @moduledoc false 14 | use Protobuf, syntax: :proto3 15 | 16 | @type t :: %__MODULE__{ 17 | filename_tensor_name: String.t(), 18 | save_tensor_name: String.t(), 19 | restore_op_name: String.t(), 20 | max_to_keep: integer, 21 | sharded: boolean, 22 | keep_checkpoint_every_n_hours: 23 | float | :infinity | :negative_infinity | :nan, 24 | version: Tensorflow.SaverDef.CheckpointFormatVersion.t() 25 | } 26 | defstruct [ 27 | :filename_tensor_name, 28 | :save_tensor_name, 29 | :restore_op_name, 30 | :max_to_keep, 31 | :sharded, 32 | :keep_checkpoint_every_n_hours, 33 | :version 34 | ] 35 | 36 | field(:filename_tensor_name, 1, type: :string) 37 | field(:save_tensor_name, 2, type: :string) 38 | field(:restore_op_name, 3, type: :string) 39 | field(:max_to_keep, 4, type: :int32) 40 | field(:sharded, 5, type: :bool) 41 | field(:keep_checkpoint_every_n_hours, 6, type: :float) 42 | 43 | field(:version, 7, 44 | type: Tensorflow.SaverDef.CheckpointFormatVersion, 45 | enum: true 46 | ) 47 | end 48 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/struct.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.TypeSpecProto.TypeSpecClass do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: 6 | integer 7 | | :UNKNOWN 8 | | :SPARSE_TENSOR_SPEC 9 | | :INDEXED_SLICES_SPEC 10 | | :RAGGED_TENSOR_SPEC 11 | | :TENSOR_ARRAY_SPEC 12 | | :DATA_DATASET_SPEC 13 | | :DATA_ITERATOR_SPEC 14 | | :OPTIONAL_SPEC 15 | | :PER_REPLICA_SPEC 16 | | :VARIABLE_SPEC 17 | | :ROW_PARTITION_SPEC 18 | | :NDARRAY_SPEC 19 | 20 | field(:UNKNOWN, 0) 21 | field(:SPARSE_TENSOR_SPEC, 1) 22 | field(:INDEXED_SLICES_SPEC, 2) 23 | field(:RAGGED_TENSOR_SPEC, 3) 24 | field(:TENSOR_ARRAY_SPEC, 4) 25 | field(:DATA_DATASET_SPEC, 5) 26 | field(:DATA_ITERATOR_SPEC, 6) 27 | field(:OPTIONAL_SPEC, 7) 28 | field(:PER_REPLICA_SPEC, 8) 29 | field(:VARIABLE_SPEC, 9) 30 | field(:ROW_PARTITION_SPEC, 10) 31 | field(:NDARRAY_SPEC, 11) 32 | end 33 | 34 | defmodule Tensorflow.StructuredValue do 35 | @moduledoc false 36 | use Protobuf, syntax: :proto3 37 | 38 | @type t :: %__MODULE__{ 39 | kind: {atom, any} 40 | } 41 | defstruct [:kind] 42 | 43 | oneof(:kind, 0) 44 | field(:none_value, 1, type: Tensorflow.NoneValue, oneof: 0) 45 | field(:float64_value, 11, type: :double, oneof: 0) 46 | field(:int64_value, 12, type: :sint64, oneof: 0) 47 | field(:string_value, 13, type: :string, oneof: 0) 48 | field(:bool_value, 14, type: :bool, oneof: 0) 49 | field(:tensor_shape_value, 31, type: Tensorflow.TensorShapeProto, oneof: 0) 50 | 51 | field(:tensor_dtype_value, 32, 52 | type: Tensorflow.DataType, 53 | enum: true, 54 | oneof: 0 55 | ) 56 | 57 | field(:tensor_spec_value, 33, type: Tensorflow.TensorSpecProto, oneof: 0) 58 | field(:type_spec_value, 34, type: Tensorflow.TypeSpecProto, oneof: 0) 59 | 60 | field(:bounded_tensor_spec_value, 35, 61 | type: Tensorflow.BoundedTensorSpecProto, 62 | oneof: 0 63 | ) 64 | 65 | field(:list_value, 51, type: Tensorflow.ListValue, oneof: 0) 66 | field(:tuple_value, 52, type: Tensorflow.TupleValue, oneof: 0) 67 | field(:dict_value, 53, type: Tensorflow.DictValue, oneof: 0) 68 | field(:named_tuple_value, 54, type: Tensorflow.NamedTupleValue, oneof: 0) 69 | end 70 | 71 | defmodule Tensorflow.NoneValue do 72 | @moduledoc false 73 | use Protobuf, syntax: :proto3 74 | 75 | @type t :: %__MODULE__{} 76 | defstruct [] 77 | end 78 | 79 | defmodule Tensorflow.ListValue do 80 | @moduledoc false 81 | use Protobuf, syntax: :proto3 82 | 83 | @type t :: %__MODULE__{ 84 | values: [Tensorflow.StructuredValue.t()] 85 | } 86 | defstruct [:values] 87 | 88 | field(:values, 1, repeated: true, type: Tensorflow.StructuredValue) 89 | end 90 | 91 | defmodule Tensorflow.TupleValue do 92 | @moduledoc false 93 | use Protobuf, syntax: :proto3 94 | 95 | @type t :: %__MODULE__{ 96 | values: [Tensorflow.StructuredValue.t()] 97 | } 98 | defstruct [:values] 99 | 100 | field(:values, 1, repeated: true, type: Tensorflow.StructuredValue) 101 | end 102 | 103 | defmodule Tensorflow.DictValue.FieldsEntry do 104 | @moduledoc false 105 | use Protobuf, map: true, syntax: :proto3 106 | 107 | @type t :: %__MODULE__{ 108 | key: String.t(), 109 | value: Tensorflow.StructuredValue.t() | nil 110 | } 111 | defstruct [:key, :value] 112 | 113 | field(:key, 1, type: :string) 114 | field(:value, 2, type: Tensorflow.StructuredValue) 115 | end 116 | 117 | defmodule Tensorflow.DictValue do 118 | @moduledoc false 119 | use Protobuf, syntax: :proto3 120 | 121 | @type t :: %__MODULE__{ 122 | fields: %{String.t() => Tensorflow.StructuredValue.t() | nil} 123 | } 124 | defstruct [:fields] 125 | 126 | field(:fields, 1, 127 | repeated: true, 128 | type: Tensorflow.DictValue.FieldsEntry, 129 | map: true 130 | ) 131 | end 132 | 133 | defmodule Tensorflow.PairValue do 134 | @moduledoc false 135 | use Protobuf, syntax: :proto3 136 | 137 | @type t :: %__MODULE__{ 138 | key: String.t(), 139 | value: Tensorflow.StructuredValue.t() | nil 140 | } 141 | defstruct [:key, :value] 142 | 143 | field(:key, 1, type: :string) 144 | field(:value, 2, type: Tensorflow.StructuredValue) 145 | end 146 | 147 | defmodule Tensorflow.NamedTupleValue do 148 | @moduledoc false 149 | use Protobuf, syntax: :proto3 150 | 151 | @type t :: %__MODULE__{ 152 | name: String.t(), 153 | values: [Tensorflow.PairValue.t()] 154 | } 155 | defstruct [:name, :values] 156 | 157 | field(:name, 1, type: :string) 158 | field(:values, 2, repeated: true, type: Tensorflow.PairValue) 159 | end 160 | 161 | defmodule Tensorflow.TensorSpecProto do 162 | @moduledoc false 163 | use Protobuf, syntax: :proto3 164 | 165 | @type t :: %__MODULE__{ 166 | name: String.t(), 167 | shape: Tensorflow.TensorShapeProto.t() | nil, 168 | dtype: Tensorflow.DataType.t() 169 | } 170 | defstruct [:name, :shape, :dtype] 171 | 172 | field(:name, 1, type: :string) 173 | field(:shape, 2, type: Tensorflow.TensorShapeProto) 174 | field(:dtype, 3, type: Tensorflow.DataType, enum: true) 175 | end 176 | 177 | defmodule Tensorflow.BoundedTensorSpecProto do 178 | @moduledoc false 179 | use Protobuf, syntax: :proto3 180 | 181 | @type t :: %__MODULE__{ 182 | name: String.t(), 183 | shape: Tensorflow.TensorShapeProto.t() | nil, 184 | dtype: Tensorflow.DataType.t(), 185 | minimum: Tensorflow.TensorProto.t() | nil, 186 | maximum: Tensorflow.TensorProto.t() | nil 187 | } 188 | defstruct [:name, :shape, :dtype, :minimum, :maximum] 189 | 190 | field(:name, 1, type: :string) 191 | field(:shape, 2, type: Tensorflow.TensorShapeProto) 192 | field(:dtype, 3, type: Tensorflow.DataType, enum: true) 193 | field(:minimum, 4, type: Tensorflow.TensorProto) 194 | field(:maximum, 5, type: Tensorflow.TensorProto) 195 | end 196 | 197 | defmodule Tensorflow.TypeSpecProto do 198 | @moduledoc false 199 | use Protobuf, syntax: :proto3 200 | 201 | @type t :: %__MODULE__{ 202 | type_spec_class: Tensorflow.TypeSpecProto.TypeSpecClass.t(), 203 | type_state: Tensorflow.StructuredValue.t() | nil, 204 | type_spec_class_name: String.t() 205 | } 206 | defstruct [:type_spec_class, :type_state, :type_spec_class_name] 207 | 208 | field(:type_spec_class, 1, 209 | type: Tensorflow.TypeSpecProto.TypeSpecClass, 210 | enum: true 211 | ) 212 | 213 | field(:type_state, 2, type: Tensorflow.StructuredValue) 214 | field(:type_spec_class_name, 3, type: :string) 215 | end 216 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/tensor_bundle.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.BundleHeaderProto.Endianness do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: integer | :LITTLE | :BIG 6 | 7 | field(:LITTLE, 0) 8 | field(:BIG, 1) 9 | end 10 | 11 | defmodule Tensorflow.BundleHeaderProto do 12 | @moduledoc false 13 | use Protobuf, syntax: :proto3 14 | 15 | @type t :: %__MODULE__{ 16 | num_shards: integer, 17 | endianness: Tensorflow.BundleHeaderProto.Endianness.t(), 18 | version: Tensorflow.VersionDef.t() | nil 19 | } 20 | defstruct [:num_shards, :endianness, :version] 21 | 22 | field(:num_shards, 1, type: :int32) 23 | 24 | field(:endianness, 2, 25 | type: Tensorflow.BundleHeaderProto.Endianness, 26 | enum: true 27 | ) 28 | 29 | field(:version, 3, type: Tensorflow.VersionDef) 30 | end 31 | 32 | defmodule Tensorflow.BundleEntryProto do 33 | @moduledoc false 34 | use Protobuf, syntax: :proto3 35 | 36 | @type t :: %__MODULE__{ 37 | dtype: Tensorflow.DataType.t(), 38 | shape: Tensorflow.TensorShapeProto.t() | nil, 39 | shard_id: integer, 40 | offset: integer, 41 | size: integer, 42 | crc32c: non_neg_integer, 43 | slices: [Tensorflow.TensorSliceProto.t()] 44 | } 45 | defstruct [:dtype, :shape, :shard_id, :offset, :size, :crc32c, :slices] 46 | 47 | field(:dtype, 1, type: Tensorflow.DataType, enum: true) 48 | field(:shape, 2, type: Tensorflow.TensorShapeProto) 49 | field(:shard_id, 3, type: :int32) 50 | field(:offset, 4, type: :int64) 51 | field(:size, 5, type: :int64) 52 | field(:crc32c, 6, type: :fixed32) 53 | field(:slices, 7, repeated: true, type: Tensorflow.TensorSliceProto) 54 | end 55 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/tensorflow_server.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.ServerDef do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | cluster: Tensorflow.ClusterDef.t() | nil, 7 | job_name: String.t(), 8 | task_index: integer, 9 | default_session_config: Tensorflow.ConfigProto.t() | nil, 10 | protocol: String.t(), 11 | port: integer, 12 | cluster_device_filters: Tensorflow.ClusterDeviceFilters.t() | nil 13 | } 14 | defstruct [ 15 | :cluster, 16 | :job_name, 17 | :task_index, 18 | :default_session_config, 19 | :protocol, 20 | :port, 21 | :cluster_device_filters 22 | ] 23 | 24 | field(:cluster, 1, type: Tensorflow.ClusterDef) 25 | field(:job_name, 2, type: :string) 26 | field(:task_index, 3, type: :int32) 27 | field(:default_session_config, 4, type: Tensorflow.ConfigProto) 28 | field(:protocol, 5, type: :string) 29 | field(:port, 6, type: :int32) 30 | field(:cluster_device_filters, 7, type: Tensorflow.ClusterDeviceFilters) 31 | end 32 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/trace_events.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.Profiler.Trace.DevicesEntry do 2 | @moduledoc false 3 | use Protobuf, map: true, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | key: non_neg_integer, 7 | value: Tensorflow.Profiler.Device.t() | nil 8 | } 9 | defstruct [:key, :value] 10 | 11 | field(:key, 1, type: :uint32) 12 | field(:value, 2, type: Tensorflow.Profiler.Device) 13 | end 14 | 15 | defmodule Tensorflow.Profiler.Trace do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | devices: %{non_neg_integer => Tensorflow.Profiler.Device.t() | nil}, 21 | trace_events: [Tensorflow.Profiler.TraceEvent.t()] 22 | } 23 | defstruct [:devices, :trace_events] 24 | 25 | field(:devices, 1, 26 | repeated: true, 27 | type: Tensorflow.Profiler.Trace.DevicesEntry, 28 | map: true 29 | ) 30 | 31 | field(:trace_events, 4, repeated: true, type: Tensorflow.Profiler.TraceEvent) 32 | end 33 | 34 | defmodule Tensorflow.Profiler.Device.ResourcesEntry do 35 | @moduledoc false 36 | use Protobuf, map: true, syntax: :proto3 37 | 38 | @type t :: %__MODULE__{ 39 | key: non_neg_integer, 40 | value: Tensorflow.Profiler.Resource.t() | nil 41 | } 42 | defstruct [:key, :value] 43 | 44 | field(:key, 1, type: :uint32) 45 | field(:value, 2, type: Tensorflow.Profiler.Resource) 46 | end 47 | 48 | defmodule Tensorflow.Profiler.Device do 49 | @moduledoc false 50 | use Protobuf, syntax: :proto3 51 | 52 | @type t :: %__MODULE__{ 53 | name: String.t(), 54 | device_id: non_neg_integer, 55 | resources: %{ 56 | non_neg_integer => Tensorflow.Profiler.Resource.t() | nil 57 | } 58 | } 59 | defstruct [:name, :device_id, :resources] 60 | 61 | field(:name, 1, type: :string) 62 | field(:device_id, 2, type: :uint32) 63 | 64 | field(:resources, 3, 65 | repeated: true, 66 | type: Tensorflow.Profiler.Device.ResourcesEntry, 67 | map: true 68 | ) 69 | end 70 | 71 | defmodule Tensorflow.Profiler.Resource do 72 | @moduledoc false 73 | use Protobuf, syntax: :proto3 74 | 75 | @type t :: %__MODULE__{ 76 | name: String.t(), 77 | resource_id: non_neg_integer 78 | } 79 | defstruct [:name, :resource_id] 80 | 81 | field(:name, 1, type: :string) 82 | field(:resource_id, 2, type: :uint32) 83 | end 84 | 85 | defmodule Tensorflow.Profiler.TraceEvent.ArgsEntry do 86 | @moduledoc false 87 | use Protobuf, map: true, syntax: :proto3 88 | 89 | @type t :: %__MODULE__{ 90 | key: String.t(), 91 | value: String.t() 92 | } 93 | defstruct [:key, :value] 94 | 95 | field(:key, 1, type: :string) 96 | field(:value, 2, type: :string) 97 | end 98 | 99 | defmodule Tensorflow.Profiler.TraceEvent do 100 | @moduledoc false 101 | use Protobuf, syntax: :proto3 102 | 103 | @type t :: %__MODULE__{ 104 | device_id: non_neg_integer, 105 | resource_id: non_neg_integer, 106 | name: String.t(), 107 | timestamp_ps: non_neg_integer, 108 | duration_ps: non_neg_integer, 109 | args: %{String.t() => String.t()} 110 | } 111 | defstruct [ 112 | :device_id, 113 | :resource_id, 114 | :name, 115 | :timestamp_ps, 116 | :duration_ps, 117 | :args 118 | ] 119 | 120 | field(:device_id, 1, type: :uint32) 121 | field(:resource_id, 2, type: :uint32) 122 | field(:name, 3, type: :string) 123 | field(:timestamp_ps, 9, type: :uint64) 124 | field(:duration_ps, 10, type: :uint64) 125 | 126 | field(:args, 11, 127 | repeated: true, 128 | type: Tensorflow.Profiler.TraceEvent.ArgsEntry, 129 | map: true 130 | ) 131 | end 132 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/trackable_object_graph.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.TrackableObjectGraph.TrackableObject.ObjectReference do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | node_id: integer, 7 | local_name: String.t() 8 | } 9 | defstruct [:node_id, :local_name] 10 | 11 | field(:node_id, 1, type: :int32) 12 | field(:local_name, 2, type: :string) 13 | end 14 | 15 | defmodule Tensorflow.TrackableObjectGraph.TrackableObject.SerializedTensor do 16 | @moduledoc false 17 | use Protobuf, syntax: :proto3 18 | 19 | @type t :: %__MODULE__{ 20 | name: String.t(), 21 | full_name: String.t(), 22 | checkpoint_key: String.t(), 23 | optional_restore: boolean 24 | } 25 | defstruct [:name, :full_name, :checkpoint_key, :optional_restore] 26 | 27 | field(:name, 1, type: :string) 28 | field(:full_name, 2, type: :string) 29 | field(:checkpoint_key, 3, type: :string) 30 | field(:optional_restore, 4, type: :bool) 31 | end 32 | 33 | defmodule Tensorflow.TrackableObjectGraph.TrackableObject.SlotVariableReference do 34 | @moduledoc false 35 | use Protobuf, syntax: :proto3 36 | 37 | @type t :: %__MODULE__{ 38 | original_variable_node_id: integer, 39 | slot_name: String.t(), 40 | slot_variable_node_id: integer 41 | } 42 | defstruct [:original_variable_node_id, :slot_name, :slot_variable_node_id] 43 | 44 | field(:original_variable_node_id, 1, type: :int32) 45 | field(:slot_name, 2, type: :string) 46 | field(:slot_variable_node_id, 3, type: :int32) 47 | end 48 | 49 | defmodule Tensorflow.TrackableObjectGraph.TrackableObject do 50 | @moduledoc false 51 | use Protobuf, syntax: :proto3 52 | 53 | @type t :: %__MODULE__{ 54 | children: [ 55 | Tensorflow.TrackableObjectGraph.TrackableObject.ObjectReference.t() 56 | ], 57 | attributes: [ 58 | Tensorflow.TrackableObjectGraph.TrackableObject.SerializedTensor.t() 59 | ], 60 | slot_variables: [ 61 | Tensorflow.TrackableObjectGraph.TrackableObject.SlotVariableReference.t() 62 | ] 63 | } 64 | defstruct [:children, :attributes, :slot_variables] 65 | 66 | field(:children, 1, 67 | repeated: true, 68 | type: Tensorflow.TrackableObjectGraph.TrackableObject.ObjectReference 69 | ) 70 | 71 | field(:attributes, 2, 72 | repeated: true, 73 | type: Tensorflow.TrackableObjectGraph.TrackableObject.SerializedTensor 74 | ) 75 | 76 | field(:slot_variables, 3, 77 | repeated: true, 78 | type: 79 | Tensorflow.TrackableObjectGraph.TrackableObject.SlotVariableReference 80 | ) 81 | end 82 | 83 | defmodule Tensorflow.TrackableObjectGraph do 84 | @moduledoc false 85 | use Protobuf, syntax: :proto3 86 | 87 | @type t :: %__MODULE__{ 88 | nodes: [Tensorflow.TrackableObjectGraph.TrackableObject.t()] 89 | } 90 | defstruct [:nodes] 91 | 92 | field(:nodes, 1, 93 | repeated: true, 94 | type: Tensorflow.TrackableObjectGraph.TrackableObject 95 | ) 96 | end 97 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/transport_options.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.RecvBufRespExtra do 2 | @moduledoc false 3 | use Protobuf, syntax: :proto3 4 | 5 | @type t :: %__MODULE__{ 6 | tensor_content: [binary] 7 | } 8 | defstruct [:tensor_content] 9 | 10 | field(:tensor_content, 1, repeated: true, type: :bytes) 11 | end 12 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/verifier_config.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule Tensorflow.VerifierConfig.Toggle do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: integer | :DEFAULT | :ON | :OFF 6 | 7 | field(:DEFAULT, 0) 8 | field(:ON, 1) 9 | field(:OFF, 2) 10 | end 11 | 12 | defmodule Tensorflow.VerifierConfig do 13 | @moduledoc false 14 | use Protobuf, syntax: :proto3 15 | 16 | @type t :: %__MODULE__{ 17 | verification_timeout_in_ms: integer, 18 | structure_verifier: Tensorflow.VerifierConfig.Toggle.t() 19 | } 20 | defstruct [:verification_timeout_in_ms, :structure_verifier] 21 | 22 | field(:verification_timeout_in_ms, 1, type: :int64) 23 | 24 | field(:structure_verifier, 2, 25 | type: Tensorflow.VerifierConfig.Toggle, 26 | enum: true 27 | ) 28 | end 29 | -------------------------------------------------------------------------------- /lib/tensorflow/core/protobuf/worker_service.pb.ex: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/tensorflow/stream_executor/dnn.pb.ex: -------------------------------------------------------------------------------- 1 | defmodule StreamExecutor.Dnn.DataType do 2 | @moduledoc false 3 | use Protobuf, enum: true, syntax: :proto3 4 | 5 | @type t :: integer | :kFloat | :kDouble | :kHalf | :kInt8 | :kInt32 6 | 7 | field(:kFloat, 0) 8 | field(:kDouble, 1) 9 | field(:kHalf, 2) 10 | field(:kInt8, 3) 11 | field(:kInt32, 4) 12 | end 13 | 14 | defmodule StreamExecutor.Dnn.DataLayout do 15 | @moduledoc false 16 | use Protobuf, enum: true, syntax: :proto3 17 | 18 | @type t :: 19 | integer 20 | | :kYXDepthBatch 21 | | :kYXBatchDepth 22 | | :kBatchYXDepth 23 | | :kBatchDepthYX 24 | | :kBatchDepthYX4 25 | 26 | field(:kYXDepthBatch, 0) 27 | field(:kYXBatchDepth, 1) 28 | field(:kBatchYXDepth, 2) 29 | field(:kBatchDepthYX, 3) 30 | field(:kBatchDepthYX4, 4) 31 | end 32 | 33 | defmodule StreamExecutor.Dnn.FilterLayout do 34 | @moduledoc false 35 | use Protobuf, enum: true, syntax: :proto3 36 | 37 | @type t :: 38 | integer 39 | | :kOutputInputYX 40 | | :kOutputYXInput 41 | | :kOutputInputYX4 42 | | :kInputYXOutput 43 | | :kYXInputOutput 44 | 45 | field(:kOutputInputYX, 0) 46 | field(:kOutputYXInput, 1) 47 | field(:kOutputInputYX4, 2) 48 | field(:kInputYXOutput, 3) 49 | field(:kYXInputOutput, 4) 50 | end 51 | 52 | defmodule StreamExecutor.Dnn.ActivationMode do 53 | @moduledoc false 54 | use Protobuf, enum: true, syntax: :proto3 55 | 56 | @type t :: 57 | integer 58 | | :kNone 59 | | :kSigmoid 60 | | :kRelu 61 | | :kRelu6 62 | | :kReluX 63 | | :kTanh 64 | | :kBandPass 65 | 66 | field(:kNone, 0) 67 | field(:kSigmoid, 1) 68 | field(:kRelu, 2) 69 | field(:kRelu6, 3) 70 | field(:kReluX, 4) 71 | field(:kTanh, 5) 72 | field(:kBandPass, 6) 73 | end 74 | 75 | defmodule StreamExecutor.Dnn.ConvolutionMode do 76 | @moduledoc false 77 | use Protobuf, enum: true, syntax: :proto3 78 | 79 | @type t :: integer | :CROSS_CORRELATION | :CONVOLUTION 80 | 81 | field(:CROSS_CORRELATION, 0) 82 | field(:CONVOLUTION, 1) 83 | end 84 | 85 | defmodule StreamExecutor.Dnn.ConvolutionKind do 86 | @moduledoc false 87 | use Protobuf, enum: true, syntax: :proto3 88 | 89 | @type t :: 90 | integer 91 | | :INVALID 92 | | :FORWARD 93 | | :BACKWARD_FILTER 94 | | :BACKWARD_DATA 95 | | :FORWARD_BIAS_ACTIVATION 96 | 97 | field(:INVALID, 0) 98 | field(:FORWARD, 1) 99 | field(:BACKWARD_FILTER, 2) 100 | field(:BACKWARD_DATA, 3) 101 | field(:FORWARD_BIAS_ACTIVATION, 4) 102 | end 103 | 104 | defmodule StreamExecutor.Dnn.AlgorithmProto.MathType do 105 | @moduledoc false 106 | use Protobuf, enum: true, syntax: :proto3 107 | 108 | @type t :: integer | :DEFAULT_MATH | :TENSOR_OP_MATH 109 | 110 | field(:DEFAULT_MATH, 0) 111 | field(:TENSOR_OP_MATH, 1) 112 | end 113 | 114 | defmodule StreamExecutor.Dnn.TensorDescriptorProto do 115 | @moduledoc false 116 | use Protobuf, syntax: :proto3 117 | 118 | @type t :: %__MODULE__{ 119 | layout_oneof: {atom, any}, 120 | dimensions: [integer], 121 | data_type: StreamExecutor.Dnn.DataType.t() 122 | } 123 | defstruct [:layout_oneof, :dimensions, :data_type] 124 | 125 | oneof(:layout_oneof, 0) 126 | field(:dimensions, 1, repeated: true, type: :int64) 127 | field(:data_type, 2, type: StreamExecutor.Dnn.DataType, enum: true) 128 | 129 | field(:data_layout, 3, 130 | type: StreamExecutor.Dnn.DataLayout, 131 | enum: true, 132 | oneof: 0 133 | ) 134 | 135 | field(:filter_layout, 4, 136 | type: StreamExecutor.Dnn.FilterLayout, 137 | enum: true, 138 | oneof: 0 139 | ) 140 | end 141 | 142 | defmodule StreamExecutor.Dnn.AlgorithmProto do 143 | @moduledoc false 144 | use Protobuf, syntax: :proto3 145 | 146 | @type t :: %__MODULE__{ 147 | algo_id: integer, 148 | math_type: StreamExecutor.Dnn.AlgorithmProto.MathType.t() 149 | } 150 | defstruct [:algo_id, :math_type] 151 | 152 | field(:algo_id, 1, type: :int64) 153 | 154 | field(:math_type, 2, 155 | type: StreamExecutor.Dnn.AlgorithmProto.MathType, 156 | enum: true 157 | ) 158 | end 159 | 160 | defmodule StreamExecutor.Dnn.ConvolutionDescriptorProto do 161 | @moduledoc false 162 | use Protobuf, syntax: :proto3 163 | 164 | @type t :: %__MODULE__{ 165 | paddings: [integer], 166 | strides: [integer], 167 | dilations: [integer], 168 | compute_mode: StreamExecutor.Dnn.DataType.t(), 169 | group_count: integer, 170 | convolution_mode: StreamExecutor.Dnn.ConvolutionMode.t(), 171 | name: String.t() 172 | } 173 | defstruct [ 174 | :paddings, 175 | :strides, 176 | :dilations, 177 | :compute_mode, 178 | :group_count, 179 | :convolution_mode, 180 | :name 181 | ] 182 | 183 | field(:paddings, 1, repeated: true, type: :int64) 184 | field(:strides, 2, repeated: true, type: :int64) 185 | field(:dilations, 3, repeated: true, type: :int64) 186 | field(:compute_mode, 4, type: StreamExecutor.Dnn.DataType, enum: true) 187 | field(:group_count, 5, type: :int32) 188 | 189 | field(:convolution_mode, 6, 190 | type: StreamExecutor.Dnn.ConvolutionMode, 191 | enum: true 192 | ) 193 | 194 | field(:name, 7, type: :string) 195 | end 196 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule Extensor.MixProject do 2 | use Mix.Project 3 | 4 | def project do 5 | [ 6 | app: :extensor, 7 | name: "Extensor", 8 | version: "2.7.0", 9 | elixir: "~> 1.10", 10 | compilers: [:elixir_make] ++ Mix.compilers(), 11 | make_cwd: "c_src", 12 | make_clean: ["clean"], 13 | description: description(), 14 | deps: deps(), 15 | package: package(), 16 | test_coverage: [tool: ExCoveralls], 17 | preferred_cli_env: [ 18 | coveralls: :test, 19 | "coveralls.html": :test, 20 | "coveralls.post": :test 21 | ], 22 | dialyzer: [ 23 | ignore_warnings: ".dialyzerignore", 24 | plt_add_deps: :transitive 25 | ], 26 | docs: [extras: ["README.md"]] 27 | ] 28 | end 29 | 30 | defp description do 31 | """ 32 | Tensorflow bindings for inference in Elixir. 33 | """ 34 | end 35 | 36 | defp deps do 37 | [ 38 | {:protobuf, "~> 0.7"}, 39 | {:google_protos, "~> 0.1"}, 40 | {:matrex, "~> 0.6", optional: true}, 41 | {:excoveralls, "~> 0.12", only: :test}, 42 | {:elixir_make, "~> 0.6", runtime: false}, 43 | {:credo, "~> 1.4", only: [:dev, :test], runtime: false}, 44 | {:dialyxir, "~> 1.0", only: [:dev], runtime: false}, 45 | {:benchee, "~> 1.0", only: :dev, runtime: false}, 46 | {:ex_doc, "~> 0.21", only: :dev, runtime: false} 47 | ] 48 | end 49 | 50 | defp package do 51 | [ 52 | files: [ 53 | "mix.exs", 54 | "README.md", 55 | "lib", 56 | "c_src/**/{*.c,*.cpp,*.h,*.hpp,Makefile,*.makefile}", 57 | "priv/.gitignore" 58 | ], 59 | maintainers: ["Brent M. Spell"], 60 | licenses: ["Apache 2.0"], 61 | links: %{ 62 | "GitHub" => "https://github.com/pylon/extensor", 63 | "Docs" => "http://hexdocs.pm/extensor/" 64 | } 65 | ] 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm", "3ad58ae787e9c7c94dd7ceda3b587ec2c64604563e049b2a0e8baafae832addb"}, 3 | "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, 4 | "certifi": {:hex, :certifi, "2.5.2", "b7cfeae9d2ed395695dd8201c57a2d019c0c43ecaf8b8bcb9320b40d6662f340", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "3b3b5f36493004ac3455966991eaf6e768ce9884693d9968055aeeeb1e575040"}, 5 | "credo": {:hex, :credo, "1.4.1", "16392f1edd2cdb1de9fe4004f5ab0ae612c92e230433968eab00aafd976282fc", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "155f8a2989ad77504de5d8291fa0d41320fdcaa6a1030472e9967f285f8c7692"}, 6 | "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, 7 | "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, 8 | "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm"}, 9 | "earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"}, 10 | "elixir_make": {:hex, :elixir_make, "0.6.1", "8faa29a5597faba999aeeb72bbb9c91694ef8068f0131192fb199f98d32994ef", [:mix], [], "hexpm", "35d33270680f8d839a4003c3e9f43afb595310a592405a00afc12de4c7f55a18"}, 11 | "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, 12 | "ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"}, 13 | "excoveralls": {:hex, :excoveralls, "0.13.3", "edc5f69218f84c2bf61b3609a22ddf1cec0fbf7d1ba79e59f4c16d42ea4347ed", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cc26f48d2f68666380b83d8aafda0fffc65dafcc8d8650358e0b61f6a99b1154"}, 14 | "exprotobuf": {:hex, :exprotobuf, "1.2.9", "f3cac1b0d0444da3c72cdfe80e394d721275dc80b1d7703ead9dad9267e93822", [:mix], [{:gpb, "~> 3.24", [hex: :gpb, repo: "hexpm", optional: false]}], "hexpm"}, 15 | "google_protos": {:hex, :google_protos, "0.1.0", "c6b9e12092d17571b093d4156d004494ca143b65dbbcbfc3ffff463ea03467c0", [:mix], [{:protobuf, "~> 0.5", [hex: :protobuf, repo: "hexpm", optional: false]}], "hexpm", "ff5564525f89d2638a4cfa9fb4d31e9ee9d9d7cb937b3e8a95f558440c039e1b"}, 16 | "gpb": {:hex, :gpb, "3.28.1", "6849b2f0004dc4e7644f4f67e7cdd18e893f0ab87eb7ad82b9cb1483ce60eed0", [:make, :rebar], [], "hexpm"}, 17 | "hackney": {:hex, :hackney, "1.16.0", "5096ac8e823e3a441477b2d187e30dd3fff1a82991a806b2003845ce72ce2d84", [:rebar3], [{:certifi, "2.5.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.0", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.6", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "3bf0bebbd5d3092a3543b783bf065165fa5d3ad4b899b836810e513064134e18"}, 18 | "idna": {:hex, :idna, "6.0.1", "1d038fb2e7668ce41fbf681d2c45902e52b3cb9e9c77b55334353b222c2ee50c", [:rebar3], [{:unicode_util_compat, "0.5.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a02c8a1c4fd601215bb0b0324c8a6986749f807ce35f25449ec9e69758708122"}, 19 | "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, 20 | "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, 21 | "makeup_elixir": {:hex, :makeup_elixir, "0.15.0", "98312c9f0d3730fde4049985a1105da5155bfe5c11e47bdc7406d88e01e4219b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "75ffa34ab1056b7e24844c90bfc62aaf6f3a37a15faa76b07bc5eba27e4a8b4a"}, 22 | "matrex": {:hex, :matrex, "0.6.8", "ccb491e661bae7931ee6b0e68f5e1cd28528e5360a59bc3ab4d759b89be1701e", [:make], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "043ef9fdd9809b012568915f2fc396ea5c5631fd792f75c1148f03d478d60901"}, 23 | "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, 24 | "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, 25 | "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, 26 | "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"}, 27 | "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, 28 | "protobuf": {:hex, :protobuf, "0.7.1", "7d1b9f7d9ecb32eccd96b0c58572de4d1c09e9e3bc414e4cb15c2dce7013f195", [:mix], [], "hexpm", "6eff7a5287963719521c82e5d5b4583fd1d7cdd89ad129f0ea7d503a50a4d13f"}, 29 | "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, 30 | "unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"}, 31 | } 32 | -------------------------------------------------------------------------------- /priv/.gitignore: -------------------------------------------------------------------------------- 1 | extensor.so 2 | -------------------------------------------------------------------------------- /test/data/pythagoras.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pylon/extensor/58fa7a06ff952020fedfc5c72f61a0b5a7f7c7bb/test/data/pythagoras.pb -------------------------------------------------------------------------------- /test/data/pythagoras/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pylon/extensor/58fa7a06ff952020fedfc5c72f61a0b5a7f7c7bb/test/data/pythagoras/saved_model.pb -------------------------------------------------------------------------------- /test/extensor/matrex_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Extensor.MatrexTest do 2 | use ExUnit.Case, async: true 3 | 4 | alias Extensor.Matrex, as: ExtensorMatrex 5 | alias Extensor.Tensor 6 | 7 | describe "matrix conversion" do 8 | test "to_tensor/1" do 9 | lol = [[1, 2], [3, 4]] 10 | 11 | # converting to a tensor 12 | assert Tensor.from_list(lol, :float) == 13 | lol |> Matrex.new() |> ExtensorMatrex.to_tensor() 14 | end 15 | 16 | test "from_tensor/1" do 17 | lol = [[1, 2], [3, 4]] 18 | 19 | # converting back to a matrix 20 | assert Matrex.new(lol) == 21 | lol |> Tensor.from_list(:float) |> ExtensorMatrex.from_tensor() 22 | 23 | # invalid type 24 | assert_raise(ArgumentError, fn -> 25 | lol |> Tensor.from_list(:double) |> ExtensorMatrex.from_tensor() 26 | end) 27 | 28 | # invalid shape 29 | assert_raise(ArgumentError, fn -> 30 | lol 31 | |> List.first() 32 | |> Tensor.from_list(:float) 33 | |> ExtensorMatrex.from_tensor() 34 | end) 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /test/extensor/session_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Extensor.SessionTest do 2 | use ExUnit.Case, async: true 3 | 4 | alias Extensor.{Session, Tensor} 5 | alias Tensorflow.{ConfigProto, GPUOptions} 6 | 7 | setup_all do 8 | # disable tensorflow debug logging 9 | System.put_env("TF_CPP_MIN_LOG_LEVEL", "3") 10 | 11 | {:ok, []} 12 | end 13 | 14 | test "custom op kernel library" do 15 | # smoke test only, building a test kernel is outside extensor's scope 16 | {:error, _e} = Session.load_library("invalid") 17 | 18 | assert_raise ErlangError, ~r/tf_error/, fn -> 19 | Session.load_library!("invalid") 20 | end 21 | 22 | :ok = Session.load_library("priv/extensor.so") 23 | Session.load_library!("priv/extensor.so") 24 | end 25 | 26 | test "parse frozen graph" do 27 | config = %{ 28 | ConfigProto.new() 29 | | gpu_options: %{GPUOptions.new() | allow_growth: true} 30 | } 31 | 32 | graph_def = File.read!("test/data/pythagoras.pb") 33 | 34 | # invalid protobuf 35 | {:error, _e} = Session.parse_frozen_graph("invalid_graph_def") 36 | 37 | assert_raise ErlangError, ~r/tf_error/, fn -> 38 | Session.parse_frozen_graph!("invalid_graph_def") 39 | end 40 | 41 | # valid protobuf 42 | {:ok, _session} = Session.parse_frozen_graph(graph_def) 43 | 44 | Session.parse_frozen_graph!(graph_def) 45 | 46 | Session.parse_frozen_graph!(graph_def, config) 47 | end 48 | 49 | test "load frozen graph file" do 50 | config = %{ 51 | ConfigProto.new() 52 | | gpu_options: %{GPUOptions.new() | allow_growth: true} 53 | } 54 | 55 | graph_path = "test/data/pythagoras.pb" 56 | 57 | # invalid file path 58 | {:error, _e} = Session.load_frozen_graph("invalid_path") 59 | 60 | assert_raise File.Error, ~r/no such file/, fn -> 61 | Session.load_frozen_graph!("invalid_path") 62 | end 63 | 64 | # valid file path 65 | {:ok, _session} = Session.load_frozen_graph(graph_path) 66 | 67 | Session.load_frozen_graph!(graph_path) 68 | 69 | Session.load_frozen_graph!(graph_path, config) 70 | end 71 | 72 | test "load saved_model directory" do 73 | config = %{ 74 | ConfigProto.new() 75 | | gpu_options: %{GPUOptions.new() | allow_growth: true} 76 | } 77 | 78 | model_path = "test/data/pythagoras" 79 | 80 | # invalid model path 81 | {:error, _e} = Session.load_saved_model("invalid_path") 82 | 83 | assert_raise ErlangError, ~r/tf_error/, fn -> 84 | Session.load_saved_model!("invalid_path") 85 | end 86 | 87 | # invalid serving tag 88 | {:error, _e} = Session.load_saved_model(model_path, config, "invalid_tag") 89 | 90 | assert_raise ErlangError, ~r/tf_error/, fn -> 91 | Session.load_saved_model!(model_path, config, "invalid_tag") 92 | end 93 | 94 | # valid model 95 | {:ok, _session} = Session.load_saved_model(model_path) 96 | 97 | Session.load_saved_model!(model_path) 98 | 99 | Session.load_saved_model!(model_path, config) 100 | 101 | Session.load_saved_model!(model_path, config, "serve") 102 | end 103 | 104 | test "run session" do 105 | session = Session.load_saved_model!("test/data/pythagoras") 106 | 107 | # missing input/output tensors 108 | input = %{ 109 | "a" => Tensor.from_list([3]), 110 | "b" => Tensor.from_list([4]) 111 | } 112 | 113 | {:error, _e} = Session.run(session, %{}, []) 114 | 115 | assert_raise ErlangError, ~r/tf_error/, fn -> 116 | Session.run!(session, %{}, []) 117 | end 118 | 119 | assert_raise ErlangError, ~r/tf_error/, fn -> 120 | Session.run!(session, input, []) 121 | end 122 | 123 | assert_raise ErlangError, ~r/tf_error/, fn -> 124 | Session.run!(session, %{}, ["c"]) 125 | end 126 | 127 | # invalid tensor name 128 | assert_raise ErlangError, ~r/invalid_tensor_name/, fn -> 129 | Session.run!(session, Map.put(input, 42, Tensor.from_list([5])), ["c"]) 130 | end 131 | 132 | assert_raise ErlangError, ~r/invalid_tensor_name/, fn -> 133 | Session.run!(session, input, [42]) 134 | end 135 | 136 | assert_raise ErlangError, ~r/tensor_not_found.*missing_tensor/, fn -> 137 | Session.run!(session, input, ["missing_tensor"]) 138 | end 139 | 140 | # invalid tensor shape 141 | input = %{ 142 | "a" => Tensor.from_list([[1], [2, 3]]), 143 | "b" => Tensor.from_list([[4], [5, 6]]) 144 | } 145 | 146 | assert_raise ArgumentError, ~r/tensor size mismatch/, fn -> 147 | Session.run!(session, input, ["c"]) 148 | end 149 | 150 | # valid tensors 151 | input = %{ 152 | "a:0" => Tensor.from_list([3]), 153 | "b:0" => Tensor.from_list([4]) 154 | } 155 | 156 | {:ok, output} = Session.run(session, input, ["c:0"]) 157 | assert Tensor.to_list(output["c:0"]) == [5] 158 | 159 | output = Session.run!(session, input, ["c:0"]) 160 | assert Tensor.to_list(output["c:0"]) == [5] 161 | 162 | # default tensor name from op name 163 | input = %{ 164 | "a" => Tensor.from_list([5]), 165 | "b" => Tensor.from_list([12]) 166 | } 167 | 168 | output = Session.run!(session, input, ["c", "c:0"]) 169 | assert Tensor.to_list(output["c"]) == [13] 170 | assert Tensor.to_list(output["c:0"]) == [13] 171 | 172 | # 1D tensor 173 | input = %{ 174 | "a" => Tensor.from_list([3, 5]), 175 | "b" => Tensor.from_list([4, 12]) 176 | } 177 | 178 | output = Session.run!(session, input, ["c", "c"]) 179 | assert Tensor.to_list(output["c"]) == [5, 13] 180 | 181 | # 2D tensor 182 | input = %{ 183 | "a" => Tensor.from_list([[3], [5]]), 184 | "b" => Tensor.from_list([[4], [12]]) 185 | } 186 | 187 | output = Session.run!(session, input, ["c"]) 188 | assert Tensor.to_list(output["c"]) == [[5], [13]] 189 | 190 | # metagraph name mapping 191 | input = %{ 192 | "a_input" => Tensor.from_list([3]), 193 | "b_input" => Tensor.from_list([4]) 194 | } 195 | 196 | {:ok, output} = Session.run(session, input, ["c_output"]) 197 | assert Tensor.to_list(output["c_output"]) == [5] 198 | 199 | # metagraph output defaults 200 | input = %{ 201 | "a_input" => Tensor.from_list([3]), 202 | "b_input" => Tensor.from_list([4]) 203 | } 204 | 205 | {:ok, output} = Session.run(session, input) 206 | assert Tensor.to_list(output["c_output"]) == [5] 207 | end 208 | 209 | test "global parallelism" do 210 | tasks = 211 | Task.async_stream( 212 | 1..100, 213 | fn _i -> 214 | input = %{ 215 | "a" => Tensor.from_list([5]), 216 | "b" => Tensor.from_list([12]) 217 | } 218 | 219 | graph_def = File.read!("test/data/pythagoras.pb") 220 | session = Session.parse_frozen_graph!(graph_def) 221 | output = Session.run!(session, input, ["c"]) 222 | assert Tensor.to_list(output["c"]) == [13] 223 | 224 | session = Session.load_saved_model!("test/data/pythagoras") 225 | output = Session.run!(session, input, ["c"]) 226 | assert Tensor.to_list(output["c"]) == [13] 227 | end, 228 | ordered: false 229 | ) 230 | 231 | Stream.run(tasks) 232 | end 233 | 234 | test "shared parallelism" do 235 | graph_def = File.read!("test/data/pythagoras.pb") 236 | session = Session.parse_frozen_graph!(graph_def) 237 | 238 | tasks = 239 | Task.async_stream( 240 | 1..10_000, 241 | fn _i -> 242 | input = %{ 243 | "a" => Tensor.from_list([5]), 244 | "b" => Tensor.from_list([12]) 245 | } 246 | 247 | output = Session.run!(session, input, ["c"]) 248 | assert Tensor.to_list(output["c"]) == [13] 249 | end, 250 | ordered: false 251 | ) 252 | 253 | Stream.run(tasks) 254 | end 255 | 256 | @tag :stress 257 | test "frozen graph stress" do 258 | graph_def = File.read!("test/data/pythagoras.pb") 259 | 260 | for _ <- 1..120_000 do 261 | Session.parse_frozen_graph!(graph_def) 262 | :erlang.garbage_collect() 263 | end 264 | end 265 | 266 | @tag :stress 267 | test "saved_model stress" do 268 | for _ <- 1..60_000 do 269 | Session.load_saved_model!("test/data/pythagoras") 270 | :erlang.garbage_collect() 271 | end 272 | end 273 | 274 | @tag :stress 275 | test "run session stress" do 276 | session = Session.load_frozen_graph!("test/data/pythagoras.pb") 277 | 278 | input = %{ 279 | "a" => Tensor.from_list(Enum.into(1..100, [])), 280 | "b" => Tensor.from_list(Enum.into(1..100, [])) 281 | } 282 | 283 | for _ <- 1..1_000_000 do 284 | Session.run!(session, input, ["c"]) 285 | :erlang.garbage_collect() 286 | end 287 | end 288 | end 289 | -------------------------------------------------------------------------------- /test/extensor/tensor_test.exs: -------------------------------------------------------------------------------- 1 | defmodule Extensor.TensorTest do 2 | use ExUnit.Case, async: true 3 | 4 | alias Extensor.Tensor 5 | 6 | @types [ 7 | :float, 8 | :double, 9 | :int32, 10 | :uint8, 11 | :int16, 12 | :int8, 13 | :int64, 14 | :bool, 15 | :qint8, 16 | :quint8, 17 | :qint32, 18 | :qint16, 19 | :quint16, 20 | :uint32, 21 | :uint64 22 | ] 23 | 24 | test "list conversion" do 25 | # empty list 26 | assert Tensor.from_list([]) === %Tensor{} 27 | assert Tensor.to_list(%Tensor{}) === [] 28 | 29 | # 1D list 30 | assert Tensor.from_list([1.1, 2.2]) === %Tensor{ 31 | type: :float, 32 | shape: {2}, 33 | data: <<1.1::native-float-32, 2.2::native-float-32>> 34 | } 35 | 36 | # 2D list 37 | assert Tensor.from_list([[1.1, 2.2], [3.3, 4.4]]) === %Tensor{ 38 | type: :float, 39 | shape: {2, 2}, 40 | data: 41 | <<1.1::native-float-32, 2.2::native-float-32, 42 | 3.3::native-float-32, 4.4::native-float-32>> 43 | } 44 | 45 | # list type serialization 46 | for t <- @types do 47 | expect = [1, 2, 3] 48 | actual = Tensor.from_list(expect, t) 49 | 50 | assert actual.type === t 51 | assert expect == Tensor.to_list(actual) 52 | end 53 | end 54 | 55 | test "validation" do 56 | # empty list 57 | assert Tensor.validate(%Tensor{}) === :ok 58 | Tensor.validate!(%Tensor{}) 59 | 60 | # 1D list 61 | assert Tensor.validate(Tensor.from_list([1.1, 2.2])) === :ok 62 | Tensor.validate!(Tensor.from_list([1.1, 2.2])) 63 | 64 | # 2D list 65 | assert Tensor.validate(Tensor.from_list([[1.1, 2.2], [3.3, 4.4]])) === :ok 66 | Tensor.validate!(Tensor.from_list([[1.1, 2.2], [3.3, 4.4]])) 67 | 68 | # list type validation 69 | for t <- @types do 70 | assert Tensor.validate(Tensor.from_list([1, 2, 3], t)) === :ok 71 | Tensor.validate!(Tensor.from_list([1, 2, 3], t)) 72 | end 73 | 74 | # invalid tensor type 75 | {:error, _e} = Tensor.validate(%Tensor{type: :invalid}) 76 | 77 | assert_raise ArgumentError, fn -> 78 | Tensor.validate!(%Tensor{type: :invalid}) 79 | end 80 | 81 | # invalid list shape 82 | {:error, _e} = Tensor.validate(Tensor.from_list([[1, 2], [3]])) 83 | 84 | assert_raise ArgumentError, fn -> 85 | Tensor.validate!(Tensor.from_list([[1, 2], [3]])) 86 | end 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /test/pythagoras.py: -------------------------------------------------------------------------------- 1 | """ simple tensorflow graph 2 | 3 | This graph computes the length of the hypotenuse of a right triangle, given 4 | the lengths of the other two sides. 5 | 6 | """ 7 | 8 | import tensorflow.compat.v1 as tf 9 | 10 | tf.disable_eager_execution() 11 | 12 | a = tf.placeholder(tf.float32, name='a') 13 | b = tf.placeholder(tf.float32, name='b') 14 | c = tf.sqrt(tf.add(tf.square(a), tf.square(b)), name='c') 15 | 16 | with tf.Session() as session: 17 | # save in frozen graph format, just a binary protocol buffer 18 | tf.train.write_graph(session.graph_def, 19 | 'test/data', 20 | 'pythagoras.pb', 21 | as_text=False) 22 | 23 | # save in the saved_model format, which can include non-const variables 24 | tf.saved_model.simple_save(session, 25 | 'test/data/pythagoras', 26 | inputs={'a_input': a, 'b_input': b}, 27 | outputs={'c_output': c}) 28 | -------------------------------------------------------------------------------- /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.configure(exclude: [:stress]) 2 | ExUnit.start() 3 | --------------------------------------------------------------------------------