Skip to content

BaseInferencer batch_size and max_seq_len cast to int #2074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

f14-bertolotti
Copy link

Motivation

mmengine supports a convenient syntax for injecting environment variables into configuration files. For instance:

infer_cfg = dict(
    # ...
    inferencer=dict(
        type=opencompass.datasets.GenInferencer,
        max_out_len="{{$MAX_OUT_LEN:2048}}",
        batch_size="{{$BATCH_SIZE:4}}"
    ),
    # ...
)

In this example, batch_size defaults to "4" unless the BATCH_SIZE environment variable is set, in which case its value is used. However, mmengine does not automatically cast the environment variable to the appropriate type, resulting in batch_size and max_out_len being passed as strings to the GenInferencer—which expects integers.

Modification

This PR adds explicit type casting for batch_size and max_out_len within BaseInferencer, ensuring they are correctly interpreted as integers regardless of whether they originate from environment variables or direct configuration.

Backward Compatibility

This change is backward compatible. Explicit casting with int() on values that are already integers has no effect, so existing configurations will continue to function as expected.

Use Cases

This enables seamless use of mmengine-style environment variable injection for batch_size and max_out_len in OpenCompass configurations.

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects.
  • CLA has been signed and all committers have signed the CLA in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants