def METHOD_NAME(value, dim_to_symbol):
    """
    Converts an unpacked tensor to a packed tensor.
    :param value: a number or tensor
    :param dim_to_symbol: a map from negative integers to characters
    """
    if isinstance(value, torch.Tensor):
        assert not hasattr(
            value, "_pyro_dims"
        ), "tried to pack an already-packed tensor"
        shape = value.shape
        shift = len(shape)
        try:
            with ignore_jit_warnings():
                dims = "".join(
                    dim_to_symbol[dim - shift]
                    for dim, size in enumerate(shape)
                    if size > 1
                )
        except KeyError as e:
            raise ValueError(
                "\n  ".join(
                    [
                        "Invalid tensor shape.",
                        "Allowed dims: {}".format(
                            ", ".join(map(str, sorted(dim_to_symbol)))
                        ),
                        "Actual shape: {}".format(tuple(value.shape)),
                        "Try adding shape assertions for your model's sample values and distribution parameters.",
                    ]
                )
            ) from e
        value = value.squeeze()
        value._pyro_dims = dims
        assert value.dim() == len(value._pyro_dims)
    return value