NameError: guild doesnt recognize defined variable?

Make sure your output scalar config is picking up the script output as expected. Use --test-output-scalars on some sample run output to see how the rules are applied. Check out the Guild File Reference for pointers.

You can evaluate the output of your latest run with this command:

guild cat --output | guild run train --test-output-scalars -

The Command Cheatsheet has some other examples to help debug operations.