
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
cut2min-bucket
Advanced tools
A PyTorch Batch Sampler that buckets by input length and cuts to min size in batch
This package provides 2 utilities:
cut2min_bucket.DatasetWrapper
to eliminate padding and cut to min size in batchcut2min_bucket.BucketBatchSampler
a batch sampler that buckets by input length.In addition, we provide a Distributed Data Parallel version of the batch sampler: cut2min_bucket.DistributedBucketBatchSampler
.
A detailed motivation for this package can be found on my blog.
Simple example:
import cut2min_bucket
import torch
import numpy as np
X = []
for _ in range(10000):
X.append(torch.tensor(np.random.randn(torch.randint(size=(), low=2, high=1000),)))
seqlens = torch.tensor([len(x) for x in X])
X = torch.nn.utils.rnn.pad_sequence(X, batch_first=True)
y = (torch.rand(10000)>0.5).int()
dataset = torch.utils.data.TensorDataset(X, y)
dataset = cut2min_bucket.DatasetWrapper(
dataset, seqlens,
index_or_key=0
)
batch_sampler = cut2min_bucket.BucketBatchSampler(
dataset,
seqlens,
batch_size=8,
n_partitions=5
)
dataloader = torch.utils.data.DataLoader(
dataset,
batch_sampler=batch_sampler,
collate_fn=dataset.collate_fn,
)
next(iter(dataloader))
FAQs
A PyTorch Batch Sampler that buckets by input length and cuts to min size in batch
We found that cut2min-bucket demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.