imitation icon indicating copy to clipboard operation
imitation copied to clipboard

Fix n_rounds is not an integer error

Open taufeeque9 opened this issue 3 years ago • 4 comments

This fix explicitly converts n_rounds to int as it can be of float type if any of the operands are float. For example, when we set total_timesteps = 1e5. The float type gives an error on line 422 in range as it requires an integer.

Alternatively, we can also ensure that total_timesteps and gen_train_timesteps are integers by explicitly converting them if given in the scientific notation.

taufeeque9 avatar Sep 14 '22 02:09 taufeeque9

Codecov Report

Merging #564 (8d08355) into master (978f74f) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #564   +/-   ##
=======================================
  Coverage   97.58%   97.58%           
=======================================
  Files          87       87           
  Lines        8557     8566    +9     
=======================================
+ Hits         8350     8359    +9     
  Misses        207      207           
Impacted Files Coverage Δ
src/imitation/scripts/train_adversarial.py 94.87% <100.00%> (+0.13%) :arrow_up:
.../imitation/scripts/train_preference_comparisons.py 97.26% <100.00%> (+0.29%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Sep 14 '22 02:09 codecov[bot]

The type signature says that total_timesteps should be an int, so it's really the caller's fault that it's passing a float in the first place.

How about making train_adversarial script do int(total_timesteps)? I think that should fix this issue and any others that are downstream of total_timesteps being the wrong type.

Alternatively we could do type validation in train_adversarial to force user to specify integer in config, e.g. int(1e5), but I feel OK about being a bit forgiving in the config format for brevity.

AdamGleave avatar Sep 14 '22 20:09 AdamGleave

How about making train_adversarial script do int(total_timesteps)? I think that should fix this issue and any others that are downstream of total_timesteps being the wrong type.

That should also fix the error. As many of the config files use the scientific notation for total_timesteps, should I make this change in all of the script files like train_imitation, train_adversarial, train_preference_comparisons, etc?

taufeeque9 avatar Sep 14 '22 21:09 taufeeque9

That should also fix the error. As many of the config files use the scientific notation for total_timesteps, should I make this change in all of the script files like train_imitation, train_adversarial, train_preference_comparisons, etc?

Making the change in all the scripts sounds good to me, thanks!

AdamGleave avatar Sep 17 '22 03:09 AdamGleave

Looks like this PR was abandoned. I took the liberty to implement what you agreed upon.

ernestum avatar Jan 17 '23 14:01 ernestum

@AdamGleave would you review this?

ernestum avatar Jan 18 '23 17:01 ernestum

Are no changes needed in train_imitation.py?

No should have mentioned it. In train_imitation.py it is already cast to int.

ernestum avatar Jan 19 '23 09:01 ernestum