Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Got unsupported ScalarType BFloat16 with OCRErrorPredictor #290

Open
kevinhu opened this issue Jan 25, 2025 · 2 comments
Open

Comments

@kevinhu
Copy link
Contributor

kevinhu commented Jan 25, 2025

I'm running Surya via Marker on a GPU, and I'm attempting to use the bfloat16 datatype. However, I'm running into this TypeError because of the order in which the cast is performed:

with torch.inference_mode():
pred = self.model(batch_input_ids, attention_mask=batch_attention_mask)
logits = pred.logits.detach().cpu().numpy().astype(np.float32)
predictions.extend(np.argmax(logits, axis=1).tolist())

This can be fixed by performing the cast before the tensors are moved to NumPy:

logits = pred.logits.to(torch.float32).detach().cpu().numpy()

When running on GPU, this should also be faster than casting in NumPy.

@VikParuchuri
Copy link
Owner

We usually use float16 for this model - any specific reason to use bfloat?

@kevinhu
Copy link
Contributor Author

kevinhu commented Jan 26, 2025

In a couple of our benchmarks, we saw that bfloat16 gives better accuracy than float16—it seems that there's some precision errors with float16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants