Skip to content

[fix](cli): keep "1" and "0" as integers in kt config set - #2201

Open
Dev-next-gen wants to merge 1 commit into
kvcache-ai:mainfrom
Dev-next-gen:fix/kt-config-set-numeric-values
Open

[fix](cli): keep "1" and "0" as integers in kt config set#2201
Dev-next-gen wants to merge 1 commit into
kvcache-ai:mainfrom
Dev-next-gen:fix/kt-config-set-numeric-values

Conversation

@Dev-next-gen

Copy link
Copy Markdown

What does this PR do?

While reading the kt CLI I noticed that kt config set stores 1 and 0 as booleans. _parse_value() in kt-kernel/python/cli/commands/config.py checks the boolean words before it tries int(), and "1"/"0" are in that list, whereas "2" goes on to become the integer 2.

Where this hurts is environment variables. After

kt config set advanced.env.CUDA_VISIBLE_DEVICES 1

the config file contains CUDA_VISIBLE_DEVICES: true, Settings.get_env_vars() stringifies it, and kt run hands sglang CUDA_VISIBLE_DEVICES=True instead of 1. The same goes for OMP_NUM_THREADS 1 or any inference.env.* value set to 1 or 0. I reproduced this on current main by calling _parse_value() and Settings against a temporary config file. I did not launch sglang itself (no NVIDIA GPU on the machine I used), so the last step, CUDA rejecting True as a device list, is what I expect rather than something I watched happen.

The change drops "1" and "0" from the boolean words so they fall through to the integer parse. true/false/yes/no/on/off still give booleans, and 0/1 keep the same truthiness, so anything that does if settings.get(...) behaves as before. I grepped the CLI for is True/== True style checks on settings values and found none.

The new CPU test kt-kernel/test/per_commit/test_config_parse_value.py fails on main with

AssertionError: {'CUDA_VISIBLE_DEVICES': 'True'} != {'CUDA_VISIBLE_DEVICES': '1'}
AssertionError: <class 'bool'> is not <class 'int'> : 0

and passes with the change. The boolean-word test passes on both sides. The test writes nothing outside its temporary directory. I ran it without building the extension, through a bare kt_kernel package that only links python/cli, so it has not been through the kt-cpu runner yet. I also didn't have black installed; the new lines stay under the 120-column limit.

No issue filed for this one.

Before submitting

AI tools used

_parse_value() checked the boolean words before trying int, and "1"/"0"
were in that list, so `kt config set advanced.env.CUDA_VISIBLE_DEVICES 1`
saved `true` and kt run exported CUDA_VISIBLE_DEVICES=True, while "2"
stayed 2. Drop "1"/"0" from the boolean words so they parse as integers.
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.

1 participant