Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

minor fix: incorrect assert string message formatting #631

Merged
merged 2 commits into from
May 24, 2019
Merged

minor fix: incorrect assert string message formatting #631

merged 2 commits into from
May 24, 2019

Conversation

bernhardschaefer
Copy link
Contributor

The assert message is split up in 2 strings:

 "SOLVER.IMS_PER_BATCH ({}) must be divisible by the number "
        "of GPUs ({}) used.".format(images_per_batch, num_gpus)

str.format() is only applied to the second string, which produces an incorrect message, where the first placeholder is not substituted and the second is incorrectly substituted.

Example: SOLVER.IMS_PER_BATCH ({}) must be divisible by the number of GPUs (32) used.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Apr 3, 2019
@fmassa
Copy link
Contributor

fmassa commented Apr 4, 2019

Are you sure that this is necessary? I tried a small example in Python 3 and it worked ok

In [16]: ("a {}"
    ...:  " bb {}".format(0, 10))
    ...:
Out[16]: 'a 0 bb 10'

The reason why we had the string split in two was because of the linter. While I would be ok breaking the linter here, I'd like to understand why my example case works.

@bernhardschaefer
Copy link
Contributor Author

bernhardschaefer commented Apr 4, 2019

I realize now that the initial description I gave in the PR is incorrect, sorry for that.
This is not about how str.format() ignores the first string when they are separated, but rather that assert only considers the first string.

Here is a small example:

In[2]: images_per_batch = 11
In[3]: num_gpus = 3
In[4]: assert (
  ...:         images_per_batch % num_gpus == 0
  ...: ), "TEST.IMS_PER_BATCH ({}) must be divisible by the number "
  ...: "of GPUs ({}) used.".format(images_per_batch, num_gpus)
  ...: 
Traceback (most recent call last):
  File "/usr/local/anaconda3/envs/sketch2bot/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3291, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-4-38b2e4ea65b1>", line 3, in <module>
    ), "TEST.IMS_PER_BATCH ({}) must be divisible by the number "
AssertionError: TEST.IMS_PER_BATCH ({}) must be divisible by the number 

To show that this is not related to IPython, here is the error I had when running the train script:

AssertionError: SOLVER.IMS_PER_BATCH ({}) must be divisible by the number
Traceback (most recent call last):
  File "tools/train_net.py", line 220, in <module>
    main()
  File "tools/train_net.py", line 213, in main
    model = train(cfg, args.local_rank, args.distributed)
  File "tools/train_net.py", line 62, in train
    start_iter=arguments["iteration"],
  File "/home/ubuntu/maskrcnn-benchmark/maskrcnn_benchmark/data/build.py", line 115, in make_data_loader
    ), "SOLVER.IMS_PER_BATCH ({}) must be divisible by the number "

@bernhardschaefer
Copy link
Contributor Author

@fmassa I added some clarification and addressed the flake8 issue that you mentioned, feel free to review again.

Copy link
Contributor

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fmassa fmassa merged commit c58550c into facebookresearch:master May 24, 2019
Lyears pushed a commit to Lyears/maskrcnn-benchmark that referenced this pull request Jun 28, 2020
…ch#631)

* do not split strings so that format() works as expected

* address flake8 indentation issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants