test_dtype.py 725 B

1234567891011121314151617
  1. import pytest
  2. import torch
  3. from petals.bloom.from_pretrained import load_pretrained_block
  4. from petals.client import DistributedBloomConfig
  5. from petals.server.block_utils import resolve_block_dtype
  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_backend_dtype(torch_dtype):
  10. config = DistributedBloomConfig.from_pretrained(MODEL_NAME)
  11. block = load_pretrained_block(MODEL_NAME, 0, config, torch_dtype=torch_dtype)
  12. backend_dtype = resolve_block_dtype(config, torch_dtype)
  13. other_backend_dtype = next(block.parameters()).dtype if torch_dtype == "auto" else torch_dtype
  14. assert backend_dtype == other_backend_dtype