- Copy the
profiling.py
somewhere into your project. - The code in
seml_sweep.py
should go into yourexperiment.py
(where your ExperimentWrapper etc is defined).
Edit your experiment's .yaml
file to conveniently turn profiling on and off:
fixed:
profiling.run_profile: True
profiling.outdir: "./"
The final profile is saved on the local filesystem and inside of MongoDB. If you have the file in the filesystem you can skip the next step.
Loading it from MongoDB is a bit annoying.
- Look up the
Object_id
. It is saved in the document of your seml run.artifacs
contains a list of artifacts (there's probably only one). Underfile_id
you find the Object id. Save in a variable calledobject_id
. - Load the object:
from seml.database import get_mongodb_config, get_database
# loads the config from your .config/seml/mongodb.config
mongodb_config = get_mongodb_config()
# get pymongo connection to MongoDB
db = get_database(**mongodb_config)
import gridfs
# load the chunked object out of MongoDBs gridFS
profile_binary = gridfs.GridFS(db).get(object_id)
# write the binary file to disk
with open("profile.speedscope", "wb") as f:
f.write(profile_binary.read(-1))
To look at the results, open https://speedscope.app and upload the profiling file. If you click on any block, it will show you the line number in your code at the bottom.
Important: To look up the Python line corresponding to the line number, make sure you're looking at the same version of the code that you profiled! If you've changed your code then lines might have moved. You can use the git commit hash to make sure you're looking at the correct version of the code. It is stored in the MongoDB by SEML during the profiling run.