forked from microsoft/DeepSpeed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make DS-Inference config readable from JSON (microsoft#2537)
- Loading branch information
Showing
2 changed files
with
60 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pytest | ||
import torch | ||
import deepspeed | ||
from unit.common import DistributedTest | ||
from unit.simple_model import create_config_from_dict | ||
|
||
|
||
@pytest.mark.inference | ||
class TestInferenceConfig(DistributedTest): | ||
world_size = 1 | ||
|
||
def test_overlap_kwargs(self): | ||
config = {"replace_with_kernel_inject": True} | ||
kwargs = {"replace_with_kernel_inject": True} | ||
|
||
engine = deepspeed.init_inference(torch.nn.Module(), config=config, **kwargs) | ||
assert engine._config.replace_with_kernel_inject | ||
|
||
def test_overlap_kwargs_conflict(self): | ||
config = {"replace_with_kernel_inject": True} | ||
kwargs = {"replace_with_kernel_inject": False} | ||
|
||
with pytest.raises(ValueError): | ||
engine = deepspeed.init_inference(torch.nn.Module(), config=config, **kwargs) | ||
|
||
def test_kwargs_and_config(self): | ||
config = {"replace_with_kernel_inject": True} | ||
kwargs = {"dtype": torch.float32} | ||
|
||
engine = deepspeed.init_inference(torch.nn.Module(), config=config, **kwargs) | ||
assert engine._config.replace_with_kernel_inject | ||
assert engine._config.dtype == kwargs["dtype"] | ||
|
||
def test_json_config(self, tmpdir): | ||
config = {"replace_with_kernel_inject": True} | ||
config_json = create_config_from_dict(tmpdir, config) | ||
|
||
engine = deepspeed.init_inference(torch.nn.Module(), config=config_json) | ||
assert engine._config.replace_with_kernel_inject |