test_dtype.py 672 B

12345678910111213141516
  1. import pytest
  2. import torch
  3. from petals.server.block_utils import resolve_block_dtype
  4. from petals.server.from_pretrained import load_pretrained_block
  5. from petals.utils.auto_config import AutoDistributedConfig
  6. from test_utils import MODEL_NAME
  7. @pytest.mark.forked
  8. @pytest.mark.parametrize("torch_dtype", [torch.float32, torch.float16, "auto"])
  9. def test_block_dtype(torch_dtype):
  10. config = AutoDistributedConfig.from_pretrained(MODEL_NAME)
  11. block = load_pretrained_block(MODEL_NAME, 0, config=config, torch_dtype=torch_dtype)
  12. expected_dtype = resolve_block_dtype(config, torch_dtype)
  13. assert all(param.dtype == expected_dtype for param in block.parameters())