I defined weights in another way, like in example you provided
class_sample_counts=[1871,229]
weights = 1. / torch.tensor(class_sample_counts, dtype=torch.float)
samples_weights = weights[train_data.y]

sampler = torch.utils.data.sampler.WeightedRandomSampler(
weights=samples_weights,
num_samples=len(samples_weights),
replacement=True)

Model is still not learning anything, my results almost the same,varying around 50% with each epoch:
…
train_acc 50.42857142857143
train_acc 50.0
train_acc 50.19047619047619
train_acc 49.0
…
Why does it happen?