Skip to content

how get os.cpu_count() in a yaml file? #824

Answered by Jasha10
jaffe-fly asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @jaffe-fly, I'd recommend using an OmegaConf custom resolver.

import os
from omegaconf import OmegaConf

OmegaConf.register_new_resolver("os_cpu_count", lambda: os.cpu_count())

my_yaml = """
trainer:
    cpu_count: ${os_cpu_count:}
"""

cfg = OmegaConf.create(my_yaml)
expected = os.cpu_count()
assert cfg.trainer.cpu_count == expected

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jaffe-fly
Comment options

Answer selected by jaffe-fly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants