How to get the instruction trace from running

Hi,

I am currently trying to get the instruction trace of running ML model inference or training. Then I decided to port these instruction traces to gem5 (architecture simulator). Can I ask how I can do this? This is not clear now because this is not like C, C++, where I can compile the program to get the assembly. I don’t even know whether it is possible to get the instruction trace or assembly from interpreter language like Python.

Many thanks!!
Edward