Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursion (wip) #2

Open
wants to merge 53 commits into
base: latest-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0ed111d
Migration Changes
GeorgeVasilakopoulos Feb 27, 2024
3458bd9
Debugging
GeorgeVasilakopoulos Feb 28, 2024
cd23277
Debugging
GeorgeVasilakopoulos Feb 28, 2024
acb668e
Added TESTS
GeorgeVasilakopoulos Mar 5, 2024
49cc2e5
Container backup 1203
GeorgeVasilakopoulos Mar 12, 2024
cb3b605
Logging & TESTS
GeorgeVasilakopoulos Mar 29, 2024
1a59ea6
Allow op_def_ to be null
GeorgeVasilakopoulos Mar 29, 2024
afa9c1e
functionality for Forward Function Declaration
GeorgeVasilakopoulos Apr 6, 2024
4992e98
forward declaration changes
GeorgeVasilakopoulos Apr 7, 2024
cd66df8
Transformation seems to be working. Commented out function inlining
GeorgeVasilakopoulos Apr 8, 2024
d7994fd
Distributed test files
GeorgeVasilakopoulos Apr 16, 2024
d60de57
Distributed Execution: code migration
GeorgeVasilakopoulos Apr 18, 2024
4aab4ea
Instructions on how to built tf in a container
GeorgeVasilakopoulos Apr 23, 2024
98aa274
minimizing changes
DelphianCalamity Apr 25, 2024
5495dd5
minimizing changes
DelphianCalamity Apr 25, 2024
09eaaf2
minimizing changes
DelphianCalamity Apr 25, 2024
eb97c74
minimizing changes
DelphianCalamity Apr 25, 2024
f544892
minimizing changes
DelphianCalamity Apr 25, 2024
585a59e
minimizing changes
DelphianCalamity Apr 25, 2024
545d7db
minimizing changes + additions in build
DelphianCalamity Apr 25, 2024
630bbb1
minimizing changes
DelphianCalamity Apr 25, 2024
3dca7bc
adding back some changes
DelphianCalamity Apr 25, 2024
a8588d4
fix
DelphianCalamity Apr 25, 2024
4e95e5e
upgrade instructions
DelphianCalamity Apr 25, 2024
9b21ab2
function_transformation should run once
GeorgeVasilakopoulos May 9, 2024
d64bddf
Skip FunctionDef creation for Return Nodes
GeorgeVasilakopoulos May 9, 2024
e51d338
flib_def could be NULL
GeorgeVasilakopoulos May 9, 2024
83e1ebc
What was intended here exactly?
GeorgeVasilakopoulos May 14, 2024
6a951c9
Fix duplicate flib imports
GeorgeVasilakopoulos May 14, 2024
bb167f8
Topological Ordering likely fixed
GeorgeVasilakopoulos May 18, 2024
8fa6cb7
Disable control flow v2 in test file
GeorgeVasilakopoulos May 18, 2024
894ea9d
Update Compilation File
GeorgeVasilakopoulos May 18, 2024
41058c8
Graph construction seems to be working
GeorgeVasilakopoulos May 20, 2024
b37b5e6
Executor changes
GeorgeVasilakopoulos May 22, 2024
8c3d37f
Include call_id when producing frame identifier
GeorgeVasilakopoulos May 23, 2024
7ad869a
Breakpoint file
GeorgeVasilakopoulos May 23, 2024
6840450
Adding some test files
GeorgeVasilakopoulos May 25, 2024
12226d2
Avoid creating self - control edges
GeorgeVasilakopoulos May 25, 2024
80dc042
Test code for how to find grad graph
GeorgeVasilakopoulos Jun 5, 2024
65deff8
Updated test file
GeorgeVasilakopoulos Jun 5, 2024
8ff57b7
Autodiff code migration. Compileable
GeorgeVasilakopoulos Jun 6, 2024
96e919c
Debugging
GeorgeVasilakopoulos Jun 6, 2024
b8d49c0
Prevent SegFault on error; Migration changes
GeorgeVasilakopoulos Jun 6, 2024
6868634
Debugging
GeorgeVasilakopoulos Jun 11, 2024
04af8f0
Updated Test file
GeorgeVasilakopoulos Jun 13, 2024
b681bd2
Debugging
GeorgeVasilakopoulos Jun 13, 2024
746700f
Enable function_optimizer
GeorgeVasilakopoulos Jun 13, 2024
d0e98a6
Remove pending check
GeorgeVasilakopoulos Jun 18, 2024
9286920
Distinguish between regular and gradient call/return nodes
GeorgeVasilakopoulos Jun 18, 2024
85172e6
Replace correctly the outputs of SymbolicGradient nodes
GeorgeVasilakopoulos Jun 19, 2024
148299d
Create gradient graph through python APIs
GeorgeVasilakopoulos Jun 23, 2024
1e4e9d9
debugging pending_count_
GeorgeVasilakopoulos Jun 23, 2024
09615b7
fixed type mismatch when func returns multiple outputs
GeorgeVasilakopoulos Jun 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions file.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
break core/common_runtime/immutable_executor_state.cc:89
continue
break core/common_runtime/direct_session.cc:918
break core/common_runtime/direct_session.cc:745
break core/common_runtime/propagator_state.cc:106
159 changes: 159 additions & 0 deletions recipe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
========================================= IN A NEW NODE ================================

1. Clone your repo

2. Install Docker

4. Install VS code extensions etc

5. Create Docker image using this Dockerfile

########### Dockerfile for my own project ################

FROM tensorflow/tensorflow:latest

RUN rm -rf /tensorflow
COPY ./tensorflow /tensorflow

RUN apt-get update && apt-get install clang -y \
&& apt-get install -y gdb \
&& apt-get install -y git

RUN echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list > /dev/null

RUN curl https://bazel.build/bazel-release.pub.gpg | apt-key add -
RUN apt update
RUN apt install -y bazel-6.5.0
RUN apt install -y bazel

RUN git clone https://github.com/GeorgeVasilakopoulos/tensorflow.git
WORKDIR tensorflow
RUN git checkout recursion

pip install --upgrade pip setuptools wheel

bazel build --config=dbg //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tensorflow_cpu
pip install bazel-bin/tensorflow/tools/pip_package/wheel_house/tensorflow_cpu-2.17.0-cp311-cp311-linux_x86_64.whl

#############################################################

6. Create a container like this


######
docker run -d --restart always -it --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -w /tensorflow -v $PWD:/mnt \
-e HOST_PERMS="\\((id -u):\\)(id -g)" my_image bash
######

=======================================================================================

CREATING KELLY'S IMAGE

1. Clone her repo

2. Build docker image using the following Dockerfile:


# docker build -t kelly_image .

############# Dockerfile for Kelly's project ################

FROM tensorflow/tensorflow:1.4.0

RUN rm -rf /tensorflow
COPY ./tensorflow /tensorflow



RUN apt-get update \
&& apt-get install -y curl wget \
&& apt-get install -y software-properties-common \
&& apt-get install -y unzip \
&& apt-get install -y git \
&& apt-get install -y gcc g++ \
&& apt-get install -y gdb
##########################################################


4. RUN

# apt-get upgrade


5. Install Conda and create virtual environment:

# cd
# wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
# chmod +x Anaconda3-2022.05-Linux-x86_64.sh
# ./Anaconda3-2022.05-Linux-x86_64.sh

...

# conda create -n venv pip python=3.7
# conda activate venv

6. Install some stuff:

pip install -U --user pip six numpy wheel setuptools mock future>=0.17.1
pip install -U --user keras_applications==1.0.6 --no-deps
pip install -U --user keras_preprocessing==1.0.5 --no-deps


7. Install bazel:

# cd
# wget https://raw.githubusercontent.com/acharal/tensorflow/recursive-functions/tensorflow/tools/ci_build/install/install_bazel.sh

# chmod +x install_bazel.sh
# ./install_bazel.sh


8. In tensorflow/workspace.bzl change the installation of cython to



##############
native.new_http_archive(
name = "cython",
sha256 = "94916d1ede67682638d3cc0feb10648ff14dc51fb7a7f147f4fedce78eaaea97",
urls = [
"https://files.pythonhosted.org/packages/f0/66/6309291b19b498b672817bd237caec787d1b18013ee659f17b1ec5844887/Cython-0.29.tar.gz",
],
strip_prefix = "Cython-0.29",
build_file = str(Label("//third_party:cython.BUILD")),
)
##############


9. Build Tensorflow as follows:


# ./configure
# bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package --cxxopt="-g" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-fpermissive"
# bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg/
# pip3 uninstall -y tensorflow
# pip3 install /tmp/tensorflow_pkg/tensorflow-1.4.2-cp37-cp37m-linux_x86_64.whl






Comments:

// RUN apt-get install -y software-properties-common
// RUN apt-get install unzip
// RUN apt-get update
// RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
// // RUN ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /mnt
// RUN apt-get install -y gcc-11 g++-11

// RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 60 --slave /usr/bin/g++ g++ /usr/bin/g++-11
// RUN wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
// RUN chmod +x Anaconda3-2022.05-Linux-x86_64.sh

// // RUN conda create -n venv pip python=3.7
// RUN wget https://raw.githubusercontent.com/acharal/tensorflow/recursive-functions/tensorflow/tools/ci_build/install/install_bazel.sh



6 changes: 6 additions & 0 deletions recursion-tests/comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd ..
bazel build --disk_cache=/root/mycache --per_file_copt=+tensorflow.*,-tensorflow/compiler.*,-tensorflow/lite.*,-tensorflow/core/kernels.*@-O0,-g //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tensorflow_cpu &&
pip uninstall tensorflow_cpu -y &&
pip install bazel-bin/tensorflow/tools/pip_package/wheel_house/tensorflow_cpu-2.17.0-cp311-cp311-linux_x86_64.whl
13 changes: 13 additions & 0 deletions recursion-tests/distributed/d2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os

os.environ['TF_CPP_MAX_VLOG_LEVEL'] = '2'

import tensorflow as tf


cluster_spec = {
"local": ["localhost:2222", "localhost:2223"]
}

server = tf.distribute.Server(cluster_spec, job_name="local", task_index=0)
server.join()
14 changes: 14 additions & 0 deletions recursion-tests/distributed/d3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os


os.environ['TF_CPP_MAX_VLOG_LEVEL'] = '2'

import tensorflow as tf


cluster_spec = {
"local": ["localhost:2222", "localhost:2223"]
}

server = tf.distribute.Server(cluster_spec, job_name="local", task_index=1)
server.join()
50 changes: 50 additions & 0 deletions recursion-tests/distributed/distr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os


os.environ['TF_CPP_MAX_VLOG_LEVEL'] = '2'

import tensorflow as tf
from tensorflow.python.framework import function

tf.compat.v1.disable_eager_execution()
tf.compat.v1.disable_control_flow_v2()


cluster = tf.train.ClusterSpec({"local": ["localhost:2222", "localhost:2223"]})

fac = function.Declare("Fac", [("n", tf.int32)], [("ret", tf.int32)])





@function.Defun(tf.int32, func_name="Fac", out_names=["ret"])
def FacImpl(n):

def f1():
with tf.device("/job:local/replica:0/task:1/device:CPU:0"):
ret = tf.constant(1)
return ret
def f2():
with tf.device("/job:local/replica:0/task:0/device:CPU:0"):
ret = n * fac(n - 1)
return ret

with tf.device("/job:local/replica:0/task:0/device:CPU:0"):
pred = tf.less_equal(n, 1)

return tf.cond(pred, f1, f2)

FacImpl.add_to_graph(tf.compat.v1.get_default_graph())

n = tf.constant(10)
x = fac(n)

#print(tf.get_default_graph().as_graph_def())

# writer = tf.compat.v1.summary.FileWriter('./graphs', tf.compat.v1.get_default_graph())

with tf.compat.v1.Session("grpc://localhost:2222") as sess:
print(sess.run(x))

# writer.close()
52 changes: 52 additions & 0 deletions recursion-tests/exponents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import tensorflow as tf
from tensorflow.python.framework import function

os.environ['TF_CPP_MAX_VLOG_LEVEL'] = '2'

tf.compat.v1.disable_eager_execution()
tf.compat.v1.disable_control_flow_v2()

exp = function.Declare("EXPONENT", [("x", tf.float32), ("n", tf.int32)], [("ret", tf.float32)])




# fac = function.Declare("Fac", [("n", tf.int32)], [("ret", tf.int32)])

@function.Defun(tf.float32, tf.int32, func_name="EXPONENT", out_names=["ret"])
def ExpImpl(x, n):
return tf.cond(tf.equal(n,0),
lambda: tf.constant(1.0),
lambda: x*exp(x,n-1))


# @function.Defun(tf.int32, func_name="Fac", out_names=["ret"])
# def FacImpl2(n):
# return t(1)


ExpImpl.add_to_graph(tf.compat.v1.get_default_graph())
# t.add_to_graph(tf.compat.v1.get_default_graph())
# FacImpl2.add_to_graph(tf.compat.v1.get_default_graph())


x = tf.compat.v1.get_variable('n_var', [], initializer=tf.constant_initializer(4.0))
y = ExpImpl(x,2)

train_op = tf.compat.v1.train.GradientDescentOptimizer(0.1).minimize(y)
print(tf.compat.v1.get_default_graph().as_graph_def())


sess = tf.compat.v1.Session()
sess.run(tf.compat.v1.initialize_all_variables())
print(x.eval(session=sess))
print(sess.run(train_op))
print(x.eval(session=sess))

# writer = tf.summary.FileWriter('./graphs', tf.compat.v1.get_default_graph())

# with tf.compat.v1.Session() as sess:
# result = ExpImpl(2,5)
# print("Result:", sess.run(result))

15 changes: 15 additions & 0 deletions recursion-tests/factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import tensorflow as tf
from tensorflow.python.framework import function

# fac = function.Declare("Fac", [("n", tf.int32)], [("ret", tf.int32)])

@function.Defun(tf.int32, func_name="Fac", out_names=["ret"])
def FacImpl(n):
return tf.cond(tf.less_equal(n, 1),
lambda: tf.constant(1),
lambda: n * FacImpl(n - 1))


print(FacImpl(5))


Empty file added recursion-tests/nohup.out
Empty file.
22 changes: 22 additions & 0 deletions recursion-tests/takeuchi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import tensorflow as tf
from tensorflow.python.framework import function

tf.compat.v1.disable_eager_execution()
tf.compat.v1.disable_control_flow_v2()

tak = function.Declare("Tak", [("x", tf.int32), ("y", tf.int32), ("z", tf.int32)], [("ret", tf.int32)])

@function.Defun(tf.int32, tf.int32, tf.int32, func_name="Tak", out_names=["ret"])
def TakImpl(x,y,z):
return tf.cond(tf.less(y, x),
lambda: tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y)),
lambda: z)

TakImpl.add_to_graph(tf.compat.v1.get_default_graph())


with tf.compat.v1.Session() as sess:
result = TakImpl(24,16,8)
print("Result:", sess.run(result))

#print(tf.get_default_graph().as_graph_def())
35 changes: 35 additions & 0 deletions recursion-tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# import os

# os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'python'


import tensorflow as tf
from tensorflow.python.framework import function


tf.compat.v1.disable_eager_execution()

# tf.logging.set_verbosity(tf.logging.INFO)
fac = function.Declare("Fac", [("n", tf.int32)], [("ret", tf.int32)])


@function.Defun(tf.int32, func_name="Test", out_names=["ret"])
def t(n):
return tf.constant(1)



# fac = function.Declare("Fac", [("n", tf.int32)], [("ret", tf.int32)])

@function.Defun(tf.int32, func_name="Fac", out_names=["ret"])
def FacImpl(n):
return t(n)



FacImpl.add_to_graph(tf.compat.v1.get_default_graph())

with tf.compat.v1.Session() as sess:
result = FacImpl(1)
print("Result:", sess.run(result))

Loading
Loading