The operations should be equal up to the error created by the limited floating point precision as seen in this example:
# setup
x = torch.randint(0, 100, (100, 10))
image_embedding = nn.Embedding(100, 300)
k = 50

# check forward
A = x[:k]
B = x[k:]
emb_A1 = image_embedding(A)
emb_B1 = image_embedding(B)

emb_all = image_embedding(x)
emb_A2 = emb_all[:k]
emb_B2 = emb_all[k:]

print((emb_A1 - emb_A2).abs().max())
print((emb_B1 - emb_B2).abs().max())

# check backward
emb_A1.mean().backward()
grad_A1 = image_embedding.weight.grad.clone()

image_embedding.zero_grad()
emb_A2.mean().backward(retain_graph=True)
grad_A2 = image_embedding.weight.grad.clone()
print((grad_A1 - grad_A2).abs().max())

emb_B1.mean().backward()
grad_B1 = image_embedding.weight.grad.clone()

image_embedding.zero_grad()
emb_B2.mean().backward()
grad_B2 = image_embedding.weight.grad.clone()
print((grad_B1 - grad_B2).abs().max())