0

I'm not too well-versed in Python, although, I think this question is mostly language-agnostic, but wanted to see if there was a particular way to do it for Python.

I'm working with a couple of Pytorch Python scripts.

The function test_qtensor_cpu on line 147 in https://github.com/pytorch/pytorch/blob/fbcode/warm/test/quantization/core/test_quantized_tensor.py is being executed when I run the script in https://github.com/pytorch/pytorch/blob/fbcode/warm/test/test_quantization.py, but I cannot find the function that calls test_qtensor_cpu. I did a grep -ri "test_qtensor_cpu*" . in the root director of this repo and the only result was the definition of this function.

Is there a way for this function to be called without explicitly writing out the function's name?

4
  • 1
    why not run with a debugger, have a breakpoint on test_qtensor_cpu and look at the call stack? Commented Nov 7, 2021 at 1:31
  • @Nullman Embarassingly, I haven't really used a debugger, but I'll try that right now and see if I can figure it out. I just started using VSCode as an IDE, which I believe has a debugger configured for it Commented Nov 7, 2021 at 1:35
  • @Nullman Can you answer my other question regarding if it's possible for this function to be executed without explicitly writing out the function's name somewhere in the code? Commented Nov 7, 2021 at 1:37
  • @SuperStormer I was thinking something along the lines of run_tests() automatically running the suite of test cases as well, but I'm not well versed enough with Python to know how this can be done Commented Nov 7, 2021 at 1:40

2 Answers 2

2

Just add:

def my_func_i_cant_figure_out_whats_calling_it()
    import traceback
    traceback.print_stack()

That will show you the callstack at that point, even without a breakpoint.

Yes, its possible to call a function without explicitly writing it out.

(and figuring out how to use a debugger is super useful... future you will thank you if you figure it out sooner rather than later)

Sign up to request clarification or add additional context in comments.

Comments

2

Line 29 of test_quantization.py imports TestQuantizedTensor (which includes the test_qtensor_cpu method).

The run_tests() (source here) at the bottom of the file will automatically run all test cases that have been imported (which includes TestQuantitizedTensor) via unittest (usually via unittest.main, though this can be changed by args passed to the test suite).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.