Skip to content

make weights loading more robust by using bounds-checked accessor#35

Closed
fps wants to merge 1 commit intomikeoliphant:mainfrom
fps:weight_loading
Closed

make weights loading more robust by using bounds-checked accessor#35
fps wants to merge 1 commit intomikeoliphant:mainfrom
fps:weight_loading

Conversation

@fps
Copy link
Copy Markdown
Contributor

@fps fps commented Apr 14, 2026

.at() has the property of being bounds-checked and that an exception is thrown in the out-of-bounds case.

@mikeoliphant
Copy link
Copy Markdown
Owner

Doing .at() for each weight is likely adding overhead. Might not be significant, but I think it makes more sense to do manual bounds checking on blocks.

@fps
Copy link
Copy Markdown
Contributor Author

fps commented Apr 14, 2026

Yes, the bounds checks add overhead, but even if it's 100 times slower, it doesn't really matter when the number of weights is 13000 or so. Maybe it will take 1 ms instead of 10 us on a core 2 duo class cpu ;)

https://www.w3tutorials.net/blog/accessing-elements-of-a-vector-in-c/#performance-comparison-speed-vs-overhead

And the weights loading is not in the time critical DSP path anyways.

@mikeoliphant
Copy link
Copy Markdown
Owner

Model load performance can be a consideration on very low powered machines, but it is more of a matter of principle than anything else. Why check bounds 100s of times when you can do it once? Plus, you can then throw a more informative error than a generic vector bounds exception.

@fps
Copy link
Copy Markdown
Contributor Author

fps commented Apr 14, 2026

OK! We'll have to agree to disagree then.

@mikeoliphant
Copy link
Copy Markdown
Owner

Addressed via 14fb7bf

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

Successfully merging this pull request may close these issues.

2 participants