line_profiler icon indicating copy to clipboard operation
line_profiler copied to clipboard

A question about recall other function from other Python.file

Open Lan1991Xu opened this issue 8 years ago • 7 comments

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 avatar Jan 13 '17 20:01 Lan1991Xu

Is the problem caused by Class agent?

Lan1991Xu avatar Jan 13 '17 20:01 Lan1991Xu

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.

rkern avatar Jan 14 '17 00:01 rkern

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 avatar Jan 14 '17 17:01 Lan1991Xu

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?

Lan1991Xu avatar Jan 14 '17 18:01 Lan1991Xu

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

rkern avatar Jan 15 '17 00:01 rkern

Yes, I solve it. Thanks

Lan1991Xu avatar Jan 18 '17 15:01 Lan1991Xu

@Lan1991Xu : How did you solve it?

mpariente avatar May 19 '18 20:05 mpariente