import io
import torch


def to_state_stream(model_state_dict):
    """Converts the given state dict to a stream of bytes."""
    _buffer = io.BytesIO()
    torch.save(model_state_dict, _buffer)
    return _buffer.getvalue()