Skip to content

ids_tensor function not defined in bert quantization tutorial #1971

Closed
@aakashb95

Description

@aakashb95

ids_tensor is called but it is not defined in the tutorial.

Potential fix:
I borrowed it from here

import random
import torch

global_rng = random.Random()

def ids_tensor(shape, vocab_size, rng=None, name=None):
    #  Creates a random int32 tensor of the shape within the vocab size
    if rng is None:
        rng = global_rng

    total_dims = 1
    for dim in shape:
        total_dims *= dim

    values = []
    for _ in range(total_dims):
        values.append(rng.randint(0, vocab_size - 1))

    return torch.tensor(data=values, dtype=torch.long, device='cpu').view(shape).contiguous()

Metadata

Metadata

Assignees

Labels

docathon-h1-2023A label for the docathon in H1 2023easyquantizationIssues relating to quantization tutorials

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions