Here is my torch.profiler output:
Some of the names I put myself, using record_function. However, things like aten::ne, I don't know what exact Python lines are calling this operation and taking up the time. Is there a way to reveal which lines are calling aten::ne, SelectBackward etc?
For aten::ne, I found through the docs that this is torch.not_equals, but I don't have it in my code anymore. It would be best if I can reveal exactly where the operations in the profiler are being called.
Related
Scenario:
create a .gd script (i.e. in GDScript)
Make it so that the script outputs an error to the Godot console.
More specifically: Make it so that the error is not a crash inside the low-level c++ code, but strictly something in the GDscript. For example, this kind of instruction: assert(false) .
This does not need to involve c++ in any way. Therefore in my opinion the location of this game error in the c++ codebase is irrelevant. All I want to know is in which GDScript this happened.
Yet, Godot says in which cpp file the error "occurred". Every time, it creates an extra line in the logs.
It slows down my work a lot: Every time, I need to read twice: First my brain makes me read that incorrect location (muscle memory: if the logs give you a stack trace, you look at the stack trace!). It takes one or two seconds for me to discard that line and read what's above: The "real" error with the "real" location of the problem (the GDscript).
Is there a way to not display the cpp file location whenever an error occurs in a GDScript?
It's not possible at the moment.
I would like to print location and function name of each function during a run.
It would help during debug to identify which function is called when multiple functions have the same name in different places.
It is possible but time costly to add by hand message such as:
println!("(function_name) file = {}, line = {}",file!(),line!());
Do you know such a solution? Have you suggestions to identify easily which function is called and who calls it?
The easiest option would probably be to use something like dtrace or ebpf: hook onto the "function entry" probe (not sure what it's called in linux / ebpf land but I'd think it exists) and just print the relevant information. You may want to add stack-based indentation though, and of course because of compiler optimisations you might have functions going missing. And you might get the mangled names which is not great, but de-mangling is a thing.
You might be able to do something similar by running your program in gdb and creating some sort of programmatic breakpoints which print and immediately continue?
Alternatively, a module-level attribute procedural macro could work: if you get a token stream for the entire module, it might be possible to automatically inject logging data into every function header.
I ran my program in Python 3.4, and it crashed. Stack trace:
Traceback (most recent call last):
[...]
File [...], line 176, in manual_setup
gammas.add((name, group_oid))
KeyError: '5733455d-ba37-48c6-b550-8f53b719310c'
Here's the code at that line. Never mind what the variables are, just that gammas is a set, as you can see:
gammas = set()
for group_oid, name, _ in self.tags:
gammas.add((name, group_oid))
By the way, name and group_oid are both str, but even if they were something unhashable, I'd get a different error.
I'm not excluding the possibility that I have something totally different going on, but before I look into weird causes I haven't even thought of yet, I'd like to know if set.add could possibly be throwing KeyError. The documentation suggests no. My knowledge of how sets work says it shouldn't. Has anyone out there seen this happen?
I checked to see if set was somehow overridden. PyCharm says it's the built-in Python set.
The only set operations that generate a KeyError are pop on an empty set and remove for an element that isn't in the set. add can't generate a KeyError.
My first guess would be that this exception is coming from the __hash__ method of name or group_oid. Inspecting those objects in a debugger could be informative. There's also the possibility it's coming from an __eq__ method.
Somehow, the Python interpreter was outputting the wrong line number and accompanying code for the error. The error was a few lines above. I should've guessed... Maybe I changed the code while it was running (How can the line numbers in my stack traces be wrong?), but I don't think I did. Anyway, it's not happening anymore.
P.S. I didn't immediately re-run and catch it because the script takes a long time to reach that point again.
What I mean by this is:
I have a program. The end user is currently using it. I submit a new piece of source code and expect it to run as if it were always there?
I can't find an answer that specifically answers the point.
I'd like to be able to say, "extend" or add new features (rather than fix something that's already there on the fly) to the program without requiring a termination of the program (eg. Restart or exit).
Yes, you can definitely do that in python.
Although, it opens a security hole, so be very careful.
You can easily do this by setting up a "loader" class that can collect the source code you want it to use and then call the exec builtin function, just pass some python source code in and it will be evaluated.
Check the package
http://opensourcehacker.com/2011/11/08/sauna-reload-the-most-awesomely-named-python-package-ever/ . It allows to overcome certain raw edges of plain exec. Also it may be worth to check Dynamically reload a class definition in Python
Inside a GUI that I have made using GUIDE in Matlab. I run into a problem where upon using the Load() function to load a .MAT file all my handles change values. This means that if I had a button that I wanted to use on my GUI. My program will believe its handle is for example
handles.button1 =190.082
when in reality the only way I can access that button any more is through a different handle that is unknown. So if its unknown lets see what its new handle must be.
findobj('Tag','button1') = 227.0093
As you can see these numbers are completely different. Why the handles values get changed is beyond me. Since the handles change I can no longer use the set() function as I have written in previous sections of code. For example I have to change
set(handles.button1, 'Enable', 'off');
to
set(findobj('Tag','button1'),'Enable','off');
Does anyone have an explanation as to why this problem occurs when using Load()?
Is there a feasible solution instead of having to find the handle for an object every time you want to use it?
The .MAT file conveniently also had a handles variable in it which overwrote my current handles.