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

Add compile-time tracked tensor shapes #63

Open
sbrunk opened this issue Oct 29, 2023 · 0 comments
Open

Add compile-time tracked tensor shapes #63

sbrunk opened this issue Oct 29, 2023 · 0 comments

Comments

@sbrunk
Copy link
Owner

sbrunk commented Oct 29, 2023

Compile-time tracked tensor shapes means that the shape of a tensor, or parts of it, is statically known at compile time.

Why?

Statically know shapes can be useful for shape-safe operations. I.e. only tensors of a certain size are allowed for some operation and the compiler will verify this.

Another reason is that as #56 has shown that in order to have correct datatype promotion, we also have to track the shape. At a minimum, we have to distinguish scalar tensors (empty shape, single number) from non-scalar tensors (any other shape). But we can also go further and track the full shape.

Like type promotion rules, we also need to track the changes of reshaping operations at compile-time where possible.

Adding compile-time shapes will probably make the Tensor type more complicated as we probably need a second parameter type for the shape. It's important that we don't complicate the API to much with this. It might also make sense to add a raw Tensor type as well as fallback.

Existing approaches

We already have lists of different approaches, so I'm just quoting them here:

#56 (comment)

... After building some more complex models, I realized the pain for named tensors/shape checking, so will take a look at that repo, and also some other resources I've found. Here is a compiled list of them:

#35 (comment)

... I recall a presentation on the TDM library. I searched and got the following, possibly interesting, links:

1. https://tongfei.me/assets/18nescala-slides.pdf
   1. https://arxiv.org/pdf/1710.06892.pdf
   2. https://tongfei.me/nexus/
2. https://www.youtube.com/watch?v=d-VbiyLwHYQ
   1. https://github.com/AnnabelleGillet/TDM
   2. https://hal.science/hal-03073789/file/IDEAS_2020_TDM_final.pdf
3. https://github.com/dieproht/matr
4. https://github.com/emptyflash/shapeless-matrix
5. https://github.com/tribbloid/shapesafe

May also be of interest:

1. https://github.com/breandan/kotlingrad
2. http://platanios.org/tensorflow_scala/guides/tensors.html
3. https://github.com/pashashiz/scanet3
4. https://arxiv.org/pdf/1801.08771.pdf

I am sure their are more out there, but this may help in the initial analysis. Maybe Scala 3's new features may make this possible, but if not done correctly, will be a maintenance headache.

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

1 participant