rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.6k stars 254 forks source link

A question about recall other function from other Python.file #81

Open Lan1991Xu opened 7 years ago

Lan1991Xu commented 7 years ago

Hi, I meet some problem when I want receive some information from about the train function . this is main function in main.py:

import tensorflow as tf
from dqn.agent import Agent
from config import Config
@profile
def main(args):
    with tf.device('/gpu:0'):
        config = tf.ConfigProto(allow_soft_placement = True)
        with tf.Session(config = config) as sess:
            config = Config() 
            player = Agent(config, sess)
            if config.isTrain:
                player.train()
            else:
                player.play() 
if __name__ == '__main__':
    tf.app.run()

This is another function named agent:

Class Agent(BaseModel):
          .....
           @profile 
    def train(self):
        # timer
        st = time.time()
        if self.isLoadFromModel:
            self.load_model()
        else:
            self.sess.run(tf.initialize_all_variables())
            self.update_target_net()
         .....

The output is:

Wrote profile results to main.py.lprof
Timer unit:1 e-06s
File: main.py
Function: main at line 6

When I run kernprof - l -v main.py, it can not print the time of train function line by line, only the information about the each line running time in main.py. I want to know is there some misunderstanding about the line_profile. Thanks

Lan1991Xu commented 7 years ago

Is the problem caused by Class agent?

rkern commented 7 years ago

Can you reduce this to a complete minimal example that the rest of us can run? And format it so that the indentation is preserved? Thanks.

If I had to guess, tensorflow is starting a subprocess that runs the code that you want to profile. tensorflow might have a configuration to run everything in the same process; I don't know.

Lan1991Xu commented 7 years ago

Hi rkern The problem is still confused me. When I run it in some complete minimal example, it works. However,the original examples still not work. i just pack this documents in dropbox https://www.dropbox.com/sh/9o259gcw187sn1o/AAD3FpRpzjTO5rucrp-RLV1Za?dl=0 There is four documents. The simple one is main1.py agent1.py. Which I call agent1.py(training function) and want to get the detail of agent1.py. It works, while the orginal one does not work. So I think this may not be the problem of Tensorflow. But what actually the problem is still not solved

Lan1991Xu commented 7 years ago

Hi Rkern Sorry, I think these problem is still exist in main1.py and agent.py. It can derectly run it, but there is no Hit Tim Per Hit %time number. I don't why?

rkern commented 7 years ago

The problem is still likely to be tf.app.run().

Lan1991Xu commented 7 years ago

Yes, I solve it. Thanks

mpariente commented 6 years ago

@Lan1991Xu : How did you solve it?