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

Code takes very long to compile on jupyter #221

Closed
cgarciae opened this issue Feb 18, 2017 · 10 comments
Closed

Code takes very long to compile on jupyter #221

cgarciae opened this issue Feb 18, 2017 · 10 comments
Milestone

Comments

@cgarciae
Copy link

This code takes very long to compile on Jupyter, I am running version 1.2.1 and also tested on coconut-develop. Since all dependencies are used inside methods you dont need the dependecies installed to test the compilation of this code on Jupyter.

class Model(object):
    
    def define_model(self, n_actions, n_states, y=0.98):
        
        with self.graph.as_default(), tf.device("cpu:0"):
            
            s = tf.placeholder(tf.int32, [None], name='s')
            a = tf.placeholder(tf.int32, [None], name='a')
            r = tf.placeholder(tf.float32, [None], name='r')
            max_Qs1 = tf.placeholder(tf.float32, [None], name='maxQs1')
            lr = tf.placeholder(tf.float32, [], name='lr')

            ops = dict(
                trainable=True, 
                kernel_initializer=tf.random_uniform_initializer(minval=0.0, maxval=0.01), 
                bias_initializer=None) #tf.random_uniform_initializer(minval=0, maxval=0.01))

            Qs = (
                s
                |> tf.one_hot$(?, n_states)
                |> tf.layers.dense$(?, n_actions, name='linear_layer', **ops)
            )

            Qsa = select_columns(Qs, a)

            max_Qs = tf.reduce_max(Qs, 1)

            error = r + y * max_Qs1 - Qsa
            loss = Pipe(error, tf.nn.l2_loss, tf.reduce_sum)
            update = tf.train.GradientDescentOptimizer(lr).minimize(loss)

        self.s = s; self.a = a; self.r = r; self.max_Qs1 = max_Qs1
        self.max_Qs = max_Qs; self.Qs = Qs; self.Qsa = Qsa; self.update = update
        self.lr = lr
                
    def choose_action(self, state, e=0.05):
        actions = self.sess.run(self.Qs, feed_dict={self.s: [state]})[0]
        n = len(actions)

        if random.random() < e:
            return random.randint(0, n-1)
        else:
            return np.argmax(actions)
        
    def get_trainer(self):
        return 1
    
    def reset(self):
        pass

    @staticmethod
    def learning_rate(t, b, k):
        return b * k / (k + t)
    
print(0)
@evhub
Copy link
Owner

evhub commented Feb 18, 2017

@cgarciae It does seem like something is slightly off with compilation under Jupyter. The whole thing takes 1.5 seconds to compile in the standard interpreter, but almost a minute on Jupyter. I'll look into it and potentially try to put out a quick v1.2.2 release with a fix.

@evhub evhub added this to the v1.2.2 milestone Feb 18, 2017
evhub added a commit that referenced this issue Feb 18, 2017
@evhub
Copy link
Owner

evhub commented Feb 18, 2017

@cgarciae I've uploaded a coconut-develop release that should hopefully make the kernel a lot faster. Let me know if it helps.

@cgarciae
Copy link
Author

Did a pip install coconut-develop --upgrade but its still taking more than 30s.

evhub added a commit that referenced this issue Feb 19, 2017
@evhub
Copy link
Owner

evhub commented Feb 19, 2017

@cgarciae Try again now. I think I got it this time!

@evhub
Copy link
Owner

evhub commented Feb 19, 2017

As far as I can tell, I believe this has been fixed. Marking as resolved and closing the issue. @cgarciae lmk if you're still experiencing any problems now on the latest coconut-develop (which will very soon be released).

@evhub evhub added the resolved label Feb 19, 2017
@evhub evhub closed this as completed Feb 19, 2017
@cgarciae
Copy link
Author

@evhub Thanks a lot! It did reduce the time, it when from 40+ seconds to 20 seconds. However, the normal python interpreter takes around 1-2 seconds, I'd say coconut should be good around 2-5 seconds given the extra effort; the coconut compiler is really takes around 2 seconds on the same file.

I can't yet use coconut like this in Jupyter, hope this gets fixed soon :)

@evhub
Copy link
Owner

evhub commented Feb 20, 2017

@cgarciae I'm going to put out v1.2.2 as is mostly to fix #219, but after that I'll try to keep working on Jupyter performance in develop.

evhub added a commit that referenced this issue Feb 20, 2017
evhub added a commit that referenced this issue Feb 20, 2017
@evhub evhub removed the resolved label Feb 20, 2017
@evhub evhub modified the milestones: v1.3.0, v1.2.2 Feb 20, 2017
@evhub evhub reopened this Feb 20, 2017
@evhub
Copy link
Owner

evhub commented Feb 20, 2017

@cgarciae As a temporary measure, if you delete the blank lines in your code (Jupyter thinks they might be where your code ends, and therefore tries to compile up to that point), you should be fine.

evhub added a commit that referenced this issue Feb 20, 2017
@evhub evhub modified the milestones: v1.3.0, v1.2.2, v1.2.3 Feb 20, 2017
@evhub
Copy link
Owner

evhub commented Feb 20, 2017

@cgarciae I just made a bunch of experimental modifications to develop which seem to have resolved the rest of the problem for me. Try it out with pip install coconut-develop and let me know if it's working for you now as well!

@cgarciae
Copy link
Author

@evhub Excellent! Now taking around 5 secconds as expected :) I am going to close the issue.

@evhub evhub mentioned this issue May 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants