Dataset Viewer
Auto-converted to Parquet Duplicate
group
stringclasses
5 values
version
stringclasses
1 value
prompt
stringlengths
48
35.8k
code_str
stringclasses
213 values
target
stringlengths
4
395
right_context_few_lines
stringlengths
1
358
library
stringclasses
1 value
api
stringlengths
6
61
torch_direct_api
v_1_10_0
import torch import torch.nn.functional as F from torch.distributed import all_reduce, get_rank, get_world_size, init_process_group def compute_world_size() -> int: rank = int(os.getenv("RANK")) # pyre-ignore[6] world_size = int(os.getenv("WORLD_SIZE")) # pyre-ignore[6] master_port = int(os.getenv("MAST...
get
get_rank()
world_size = get_world_size() t = F.one_hot(torch.tensor(rank), num_classes=world_size) all_reduce(t)
torch
torch.distributed.get_rank
torch_direct_api
v_1_10_0
import torch import torch.nn.functional as F from torch.distributed import all_reduce, get_rank, get_world_size, init_process_group def compute_world_size() -> int: rank = int(os.getenv("RANK")) # pyre-ignore[6] world_size = int(os.getenv("WORLD_SIZE")) # pyre-ignore[6] master_port = int(os.getenv("MAST...
get
get_world_size()
t = F.one_hot(torch.tensor(rank), num_classes=world_size) all_reduce(t) computed_world_size = int(torch.sum(t).item())
torch
torch.distributed.get_world_size
torch_direct_api
v_1_10_0
import torch import torch.nn.functional as F from torch.distributed import all_reduce, get_rank, get_world_size, init_process_group def compute_world_size() -> int: rank = int(os.getenv("RANK")) # pyre-ignore[6] world_size = int(os.getenv("WORLD_SIZE")) # pyre-ignore[6] master_port = int(os.getenv("MAST...
F
F.one_hot(torch.tensor(rank), num_classes=world_size)
all_reduce(t) computed_world_size = int(torch.sum(t).item()) print( f"rank: {rank}, actual world_size: {world_size}, computed world_size: {computed_world_size}"
torch
torch.nn.functional.one_hot
torch_direct_api
v_1_10_0
import torch import torch.distributed as dist from torch.distributed.distributed_c10d import _get_default_group def local_device() -> torch.device: """ Returns the device that the current process should be using for models and tensors based on the default process group. .. note:: If the process group...
_get_default_group()
return ( local_cuda_device() if default_pg.options.backend == "nccl" else torch.device("cpu")
torch
torch.distributed.distributed_c10d._get_default_group
torch_direct_api
v_1_10_0
import torch import torch.jit from torch.nn import functional as F class TinyImageNetModel(pl.LightningModule): """ An very simple linear model for the tiny image net dataset. """ def __init__( self, layer_sizes: Optional[List[int]] = None, lr: Optional[float] = None ) -> None: su...
torch
torch.nn.AdaptiveAvgPool2d(1)
m.fc.out_features = 200 self.model: ResNet = m self.train_acc = Accuracy()
torch
torch.nn.AdaptiveAvgPool2d
torch_direct_api
v_1_10_0
import torch import torch.jit from torch.nn import functional as F def export_inference_model( model: TinyImageNetModel, out_path: str, tmpdir: str ) -> None: """ export_inference_model uses TorchScript JIT to serialize the TinyImageNetModel into a standalone file that can be used during inference. ...
torch
torch.jit.script(model)
print(f"saving JIT model to {jit_path}") torch.jit.save(jitted, jit_path) model_name = "tiny_image_net"
torch
torch.jit.script
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter class Net(nn.Module): def __init__(self) -> None: super(Net, self).__init__() self.c...
nn
nn.Conv2d(1, 32, 3, 1)
self.conv2 = nn.Conv2d(32, 64, 3, 1) self.dropout1 = nn.Dropout(0.25) self.dropout2 = nn.Dropout(0.5) self.fc1 = nn.Linear(9216, 128)
torch
torch.nn.Conv2d
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter class Net(nn.Module): def __init__(self) -> None: super(Net, self).__init__() self.c...
nn
nn.Dropout(0.25)
self.dropout2 = nn.Dropout(0.5) self.fc1 = nn.Linear(9216, 128) self.fc2 = nn.Linear(128, 10)
torch
torch.nn.Dropout
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter class Net(nn.Module): def __init__(self) -> None: super(Net, self).__init__() self.c...
nn
nn.Linear(9216, 128)
self.fc2 = nn.Linear(128, 10) def forward(self, x: Tensor) -> Tensor: x = self.conv1(x)
torch
torch.nn.Linear
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter class Net(nn.Module): def __init__(self) -> None: super(Net, self).__init__() self.c...
F
F.relu(x)
x = self.conv2(x) x = F.relu(x) x = F.max_pool2d(x, 2) x = self.dropout1(x)
torch
torch.nn.functional.relu
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter class Net(nn.Module): def __init__(self) -> None: super(Net, self).__init__() self.c...
F
F.max_pool2d(x, 2)
x = self.dropout1(x) x = torch.flatten(x, 1) x = self.fc1(x) x = F.relu(x)
torch
torch.nn.functional.max_pool2d
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter class Net(nn.Module): def __init__(self) -> None: super(Net, self).__init__() self.c...
torch
torch.flatten(x, 1)
x = self.fc1(x) x = F.relu(x) x = self.dropout2(x) x = self.fc2(x)
torch
torch.flatten
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter class Net(nn.Module): def __init__(self) -> None: super(Net, self).__init__() self.c...
F
F.log_softmax(x, dim=1)
return output def train(
torch
torch.nn.functional.log_softmax
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter def train( args: Namespace, model: nn.Module, device: torch.device, train_loader: torch....
F
F.nll_loss(output, target)
loss.backward() optimizer.step() if batch_idx % args.log_interval == 0: print(
torch
torch.nn.functional.nll_loss
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter def main() -> None: parser = argparse.ArgumentParser(description="PyTorch MNIST Example") parser...
torch
torch.device("cuda" if use_cuda else "cpu")
train_kwargs = {"batch_size": args.batch_size} test_kwargs = {"batch_size": args.test_batch_size} if use_cuda:
torch
torch.device
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter def main() -> None: parser = argparse.ArgumentParser(description="PyTorch MNIST Example") parser...
torch
torch.utils.data.DataLoader(dataset1, **train_kwargs)
test_loader = torch.utils.data.DataLoader(dataset2, **test_kwargs) model = Net().to(device) optimizer = optim.Adadelta(model.parameters(), lr=args.lr)
torch
torch.utils.data.DataLoader
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter def main() -> None: parser = argparse.ArgumentParser(description="PyTorch MNIST Example") parser...
optim
optim.Adadelta(model.parameters(), lr=args.lr)
scheduler = StepLR(optimizer, step_size=1, gamma=args.gamma)
torch
torch.optim.Adadelta
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter def main() -> None: parser = argparse.ArgumentParser(description="PyTorch MNIST Example") parser...
StepLR
StepLR(optimizer, step_size=1, gamma=args.gamma)
app_run = tracker.app_run_from_env()
torch
torch.optim.lr_scheduler.StepLR
torch_direct_api
v_1_10_0
import torch import torch.nn as nn import torch.nn.functional as F import torch.optim as optim from torch import Tensor from torch.optim.lr_scheduler import StepLR from torch.utils.tensorboard import SummaryWriter def main() -> None: parser = argparse.ArgumentParser(description="PyTorch MNIST Example") parser...
SummaryWriter
SummaryWriter(log_dir=args.tb_log_path)
app_run.add_artifact("tensorboard", args.tb_log_path) for epoch in range(1, args.epochs + 1):
torch
torch.utils.tensorboard.SummaryWriter
torch_direct_api
v_1_10_0
import torch from torch.testing._internal.common_utils import TestCase, run_tests class TestMinifier(TestCase): def test_has_mul_minifier(self): def failing_f(x, y): y = y / 3 x = x + 3 x = x * y return x + y inps = [
torch
torch.randn(3)
, torch.randn(3)] failing_f = make_fx(failing_f)(*inps) def pass_checker(fx_g, inps): return (torch.ops.aten.mul in set([i.target for i in fx_g.graph.nodes]))
torch
torch.randn
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import TestCase, run_tests import torch import torch.nn as nn import torch.utils._pytree as pytree from torch.testing._internal.common_device_type import instantiate_device_type_tests from torch.testing._internal.common_device_type import ops class TestAOTAutograd(TestCase): ...
torch
torch.exp(x)
z = torch.autograd.grad(y, x) return z inps = [torch.randn((), requires_grad=True)] self.verify_aot_autograd(foo, inps)
torch
torch.exp
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import TestCase, run_tests import torch import torch.nn as nn import torch.utils._pytree as pytree from torch.testing._internal.common_device_type import instantiate_device_type_tests from torch.testing._internal.common_device_type import ops class TestAOTAutograd(TestCase): ...
torch
torch.autograd.grad(y, x)
return z inps = [torch.randn((), requires_grad=True)] self.verify_aot_autograd(foo, inps)
torch
torch.autograd.grad
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import TestCase, run_tests import torch import torch.nn as nn import torch.utils._pytree as pytree from torch.testing._internal.common_device_type import instantiate_device_type_tests from torch.testing._internal.common_device_type import ops class TestAOTAutograd(TestCase): ...
nn
nn.Sequential(nn.Linear(32, 32), nn.ReLU())
compiled_mod = compiled_module(mod, nop, nop) inp = torch.randn(32, 32) ref_out = mod(inp) ref_out.sum().backward()
torch
torch.nn.Sequential
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import TestCase, run_tests import torch import torch.nn as nn import torch.utils._pytree as pytree from torch.testing._internal.common_device_type import instantiate_device_type_tests from torch.testing._internal.common_device_type import ops class TestAOTAutograd(TestCase): ...
torch
torch.ones(1, 4, 2, 2)
mod(x).sum().backward() class TestEagerFusionOpInfo(TestCase):
torch
torch.ones
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import TestCase, run_tests import torch import torch.nn as nn import torch.utils._pytree as pytree from torch.testing._internal.common_device_type import instantiate_device_type_tests from torch.testing._internal.common_device_type import ops class TestEagerFusionOpInfo(TestC...
pytree
pytree.tree_map(create_new_arg, args)
reset_grads() compiled_f(args, kwargs).sum().backward() compiled_grad = get_grads(args)
torch
torch.utils._pytree.tree_map
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import TestCase, run_tests import torch import torch.nn as nn import torch.utils._pytree as pytree from torch.testing._internal.common_device_type import instantiate_device_type_tests from torch.testing._internal.common_device_type import ops class TestPartitioning(TestCase):...
torch
torch.rand(10, 10, requires_grad=True)
ref_b = torch.rand(10, 10, requires_grad=True) ref = fn(ref_a, ref_b) ref.sum().backward()
torch
torch.rand
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
torch
torch.randint(0, C, (N,), device=device)
def foo(y, targets): return F.cross_entropy(y, targets)
torch
torch.randint
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
torch
torch.tensor([1., 2., 3.], device=device)
captured = torch.randn(3, device=device) def foo(x): captured.copy_(x)
torch
torch.tensor
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
torch
torch.cos(y)
return z1 + z2 result = foo(x, y) grads = torch.autograd.grad(result, [x, y])
torch
torch.cos
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
torch
torch.zeros_like(x)
,) self.assertEqual(result, expected) def test_unrelated_vjp_multiple_inputs_outputs(self, device): w = torch.tensor(3., device=device)
torch
torch.zeros_like
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
torch
torch.zeros(N, M, M, device=device)
self.assertEqual(result, expected) def test_vjp_pytree_input(self, device): def f(x):
torch
torch.zeros
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
nn
nn.Linear(2, self.hidden_dim)
self.fc2 = nn.Linear(self.hidden_dim, self.n_classes) def forward(self, x): x = self.fc1(x)
torch
torch.nn.Linear
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
F
F.relu(x)
x = self.fc2(x) x = F.log_softmax(x, -1) return x
torch
torch.nn.functional.relu
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
F
F.log_softmax(x, -1)
return x B = 10 weights, fn, _ = functional_init(MLPClassifier, (B,), device=device)(32, 2)
torch
torch.nn.functional.log_softmax
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
nn
nn.BatchNorm1d(self.hidden_dim, affine=True)
self.fc2 = nn.Linear(self.hidden_dim, self.n_classes) def forward(self, x): x = self.fc1(x)
torch
torch.nn.BatchNorm1d
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
torch
torch.stack(expected)
self.assertEqual(result, expected, atol=0, rtol=5e-4) def test_new_zeros_materializes_tensor(self, device):
torch
torch.stack
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
nn
nn.Embedding(vocab_size, 16)
self.fc1 = nn.Linear(16, 16) self.fc2 = nn.Linear(16, 2) def forward(self, x):
torch
torch.nn.Embedding
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
torch
torch.transpose(x, -1, -2)
x = torch.mean(x, -1) x = self.fc1(x) x = F.relu(x) x = self.fc2(x)
torch
torch.transpose
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
torch
torch.mean(x, -1)
x = self.fc1(x) x = F.relu(x) x = self.fc2(x) return x
torch
torch.mean
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
nn
nn.CrossEntropyLoss()
net_func, weights = make_functional(net) def compute_loss(weights, data, target):
torch
torch.nn.CrossEntropyLoss
torch_direct_api
v_1_10_0
from torch.testing._internal.common_utils import ( TestCase, run_tests, parametrize, subtest import torch import torch.nn as nn import torch.nn.functional as F from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyCPU from torch.testing._internal.common_dtype import get_all_fp_dtypes...
torch
torch.log_softmax(x, dim=-1)
output.backward(v) self.assertEqual(result, x.grad)
torch
torch.log_softmax
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
9