Skip to content

Commit c2ccc5a

Browse files
authored
[Go] Update Go API installation guide for TensorFlow 2.12.0 (#144)
1 parent 23986ca commit c2ccc5a

2 files changed

Lines changed: 31 additions & 15 deletions

File tree

‎golang_install_guide/README.md‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ repo, and with one of the following import statements:
4848

4949
| TensorFlow C API | Graft |
5050
| :------------------------ | :-------------------------------------------------------------------------------------------------- |
51-
| TensorFlow Release 2.11.0 | [`go get github.com/wamuir/graft/tensorflow@v0.3.0`](https://github.com/wamuir/graft/tree/v0.3.0) |
52-
| TensorFlow Release 2.10.1 | [`go get github.com/wamuir/graft/tensorflow@v0.2.1`](https://github.com/wamuir/graft/tree/v0.2.1) |
53-
| TensorFlow Release 2.9.3 | [`go get github.com/wamuir/graft/tensorflow@v0.1.2`](https://github.com/wamuir/graft/tree/v0.1.2) |
51+
| TensorFlow Release 2.12.0 | [`go get github.com/wamuir/graft/tensorflow@v0.4.0`](https://github.com/wamuir/graft/tree/v0.4.0) |
52+
| TensorFlow Release 2.11.1 | [`go get github.com/wamuir/graft/tensorflow@v0.3.1`](https://github.com/wamuir/graft/tree/v0.3.1) |
5453
| TensorFlow Nightly | [`go get github.com/wamuir/graft/tensorflow@nightly`](https://github.com/wamuir/graft/tree/nightly) |
5554

5655

@@ -59,14 +58,16 @@ repo, and with one of the following import statements:
5958
<details>
6059
<summary>Click to expand</summary>
6160

61+
> Note: these build instructions are specific to TensorFlow 2.12.0
62+
6263
### 1. Install the TensorFlow C Library
6364

6465
Install the [TensorFlow C library](https://www.tensorflow.org/install/lang_c). This
6566
library is required for use of the TensorFlow Go package at runtime. For example,
6667
on Linux (64-bit, x86):
6768

6869
```sh
69-
$ curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.11.0.tar.gz | tar xz --directory /usr/local
70+
$ curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.12.0.tar.gz | tar xz --directory /usr/local
7071
$ ldconfig
7172
```
7273

@@ -104,7 +105,7 @@ Instead, follow these instructions.***
104105
workspace for `/go` in the command below.
105106

106107
```sh
107-
$ git clone --branch v2.11.0 https://github.com/tensorflow/tensorflow.git /go/src/github.com/tensorflow/tensorflow
108+
$ git clone --branch v2.12.0 https://github.com/tensorflow/tensorflow.git /go/src/github.com/tensorflow/tensorflow
108109
```
109110

110111
- Change the working directory to the base of the cloned TensorFlow repository,
@@ -121,10 +122,20 @@ Instead, follow these instructions.***
121122
$ go mod init github.com/tensorflow/tensorflow
122123
```
123124

124-
- Patch tensorflow/go/genop to generate TSL protobufs.
125+
- Patch protos to declare Go package.
126+
127+
```sh
128+
$ sed -i '4 i option go_package = "github.com\/tensorflow\/tensorflow\/tensorflow\/go\/core\/framework\/dataset_go_proto";' tensorflow/core/framework/dataset.proto
129+
$ sed -i '4 i option go_package = "github.com\/tensorflow\/tensorflow\/tensorflow\/go\/core\/framework\/optimized_function_graph_go_proto";' tensorflow/core/framework/optimized_function_graph.proto
130+
$ sed -i '4 i option go_package = "github.com\/google\/tsl\/tsl\/go\/core\/protobuf\/for_core_protos_go_proto";;' tensorflow/tsl/protobuf/test_log.proto
131+
```
132+
133+
- Patch tensorflow/go/genop to generate TF and TSL protobufs.
125134

126135
```sh
127-
$ sed -i '72 i \ ${TF_DIR}\/tensorflow\/tsl\/protobuf\/*.proto \\' tensorflow/go/genop/generate.sh
136+
$ sed -i '71d;72d' tensorflow/go/genop/generate.sh
137+
$ sed -i '71 i \ ${TF_DIR}\/tensorflow\/tsl\/protobuf\/*.proto \\' tensorflow/go/genop/generate.sh
138+
$ sed -i '72 i \ ${TF_DIR}\/tensorflow\/compiler\/xla\/stream_executor\/dnn.proto; do' tensorflow/go/genop/generate.sh
128139
```
129140

130141
- Generate wrappers and protocol buffers.
@@ -171,7 +182,7 @@ workspace for `/go` in the command below:
171182
```sh
172183
$ go mod init hello-world
173184
$ go mod edit -require github.com/google/tsl@v0.0.0+incompatible
174-
$ go mod edit -require github.com/tensorflow/tensorflow@v2.11.0+incompatible
185+
$ go mod edit -require github.com/tensorflow/tensorflow@v2.12.0+incompatible
175186
$ go mod edit -replace github.com/google/tsl=/go/src/github.com/google/tsl
176187
$ go mod edit -replace github.com/tensorflow/tensorflow=/go/src/github.com/tensorflow/tensorflow
177188
$ go mod tidy
@@ -219,7 +230,7 @@ func main() {
219230
```sh
220231
$ go mod init app
221232
$ go mod edit -require github.com/google/tsl@v0.0.0+incompatible
222-
$ go mod edit -require github.com/tensorflow/tensorflow@v2.11.0+incompatible
233+
$ go mod edit -require github.com/tensorflow/tensorflow@v2.12.0+incompatible
223234
$ go mod edit -replace github.com/google/tsl=/go/src/github.com/google/tsl
224235
$ go mod edit -replace github.com/tensorflow/tensorflow=/go/src/github.com/tensorflow/tensorflow
225236
$ go mod tidy

‎golang_install_guide/example-program/Dockerfile‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
# ============================================================================
1515

1616

17-
FROM golang:1.19-bullseye
17+
FROM golang:1.20-bullseye
1818

19-
# 1. Install the TensorFlow C Library (v2.11.0).
20-
RUN curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-$(uname -m)-2.11.0.tar.gz \
19+
# 1. Install the TensorFlow C Library (v2.12.0).
20+
RUN curl -L https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-$(uname -m)-2.12.0.tar.gz \
2121
| tar xz --directory /usr/local \
2222
&& ldconfig
2323

@@ -27,10 +27,15 @@ RUN apt-get update && apt-get -y install --no-install-recommends \
2727
protobuf-compiler
2828

2929
# 3. Install and Setup the TensorFlow Go API.
30-
RUN git clone --branch=v2.11.0 https://github.com/tensorflow/tensorflow.git /go/src/github.com/tensorflow/tensorflow \
30+
RUN git clone --branch=v2.12.0 https://github.com/tensorflow/tensorflow.git /go/src/github.com/tensorflow/tensorflow \
3131
&& cd /go/src/github.com/tensorflow/tensorflow \
3232
&& go mod init github.com/tensorflow/tensorflow \
33-
&& sed -i '72 i \ ${TF_DIR}\/tensorflow\/tsl\/protobuf\/*.proto \\' tensorflow/go/genop/generate.sh \
33+
&& sed -i '4 i option go_package = "github.com\/tensorflow\/tensorflow\/tensorflow\/go\/core\/framework\/dataset_go_proto";' tensorflow/core/framework/dataset.proto \
34+
&& sed -i '4 i option go_package = "github.com\/tensorflow\/tensorflow\/tensorflow\/go\/core\/framework\/optimized_function_graph_go_proto";' tensorflow/core/framework/optimized_function_graph.proto \
35+
&& sed -i '4 i option go_package = "github.com\/google\/tsl\/tsl\/go\/core\/protobuf\/for_core_protos_go_proto";;' tensorflow/tsl/protobuf/test_log.proto \
36+
&& sed -i '71d;72d' tensorflow/go/genop/generate.sh \
37+
&& sed -i '71 i \ ${TF_DIR}\/tensorflow\/tsl\/protobuf\/*.proto \\' tensorflow/go/genop/generate.sh \
38+
&& sed -i '72 i \ ${TF_DIR}\/tensorflow\/compiler\/xla\/stream_executor\/dnn.proto; do' tensorflow/go/genop/generate.sh \
3439
&& (cd tensorflow/go/op && go generate) \
3540
&& go mod edit -require github.com/google/tsl@v0.0.0+incompatible \
3641
&& go mod edit -replace github.com/google/tsl=/go/src/github.com/google/tsl \
@@ -43,7 +48,7 @@ WORKDIR /example-program
4348
COPY hello_tf.go .
4449
RUN go mod init app \
4550
&& go mod edit -require github.com/google/tsl@v0.0.0+incompatible \
46-
&& go mod edit -require github.com/tensorflow/tensorflow@v2.11.0+incompatible \
51+
&& go mod edit -require github.com/tensorflow/tensorflow@v2.12.0+incompatible \
4752
&& go mod edit -replace github.com/google/tsl=/go/src/github.com/google/tsl \
4853
&& go mod edit -replace github.com/tensorflow/tensorflow=/go/src/github.com/tensorflow/tensorflow \
4954
&& go mod tidy \

0 commit comments

Comments
 (0)