Comments (4)
I've started messing around with named tensors. My opinion is that we should enforce names as a requirement. I think the benefits of enforcing name requirements outweigh the possible annoyance or verbosity in the code. I think it also avoids us having to make decisions about how to preserve names in instances where one tensor's names are explicitly defined and another's aren't.
For example, if somebody tries to do:
Nx.add(Nx.tensor([1, 2, 3]), Nx.tensor([1, 2, 3], names: [:data])
Then we either have to drop the name altogether and it may be difficult to try to find out where the name got dropped or changed if it needs to be used later on or we have to raise here and enforce ops like this to work only with tensors that are all named or all unnamed.
If we force people to always name their tensors, then we have:
Nx.add(Nx.tensor([1, 2, 3], names: [:batch]), Nx.tensor([1, 2, 3], names: [:data]))
And it's to clear to see this shouldn't work. Then with broadcasting we just align the names and broadcast the data. What are your thoughts?
from nx.
My concern with enforcing names is that we lose the ability for general algorithms that work on any shape - that's why I am a bit hesitant of enforcing them. I also think it will make playing with the library for discovery a bit more uncomfortable (think about rewriting all examples to include names...).
Luckily, for the cases where one has name and the other does not, we should preserve the names of the one with names. The bigger question is what to do when there is a broadcast and some of those names do not have shapes. We will probably need to allow some of the names to be nil
.
from nx.
I think then we should by default initialize all the names to nil
unless the names of a dimension are given as a list atoms. Then handling broadcasting would be easy.
So :names
would be an option in all of the tensor creation methods that defaults to a list of nil
matching the rank of the tensor. If :names
is given by the user, it must have the same length as the rank of the tensor.
As far as default names go, I don't think we should provide generic defaults because I think the "defaults" really come with your application.
Anybody who's working with images will have the dimensions:
:batch, :height, :width, :channels
And other domains would inevitably have their own sort of consistent naming conventions. And then the responsibility is on whoever is writing an algorithm to document what their chosen naming standard is.
from nx.
from nx.
Related Issues (20)
- Convert Nx.LinAlg.qr to optional callback HOT 1
- Convert Nx.LinAlg.cholesky to optional callback
- Fix sign of zero values in Nx.ceil and Nx.conjugate HOT 1
- Add executable-level caching to Nx.Defn in EXLA HOT 1
- Nx.LinAlg.solve/2 with Nx.BinaryBackend returns tensor with wrong state HOT 6
- Nx.all_close not working with EXLA HOT 13
- How to Set XLA log level?? HOT 2
- could not compile dependency :exla HOT 3
- Implement Nx.stack as a default callback
- Expand docs for the :axes option in Nx.gather/3 HOT 2
- Remove xla compiler_mode
- Use regions when compiling `if` in MLIR HOT 1
- Quantization via MLIR
- Special node acceleration via metadata HOT 6
- Import and export of MLIR modules
- function Torchx.__jit__/5 is undefined or private HOT 2
- Geometric / Clifford algebra in arbitrary dimensions HOT 4
- Automatically track which variables are inside if/cond/while
- Data Loaders in Nx? HOT 6
- Cannot transform dummy columns to Nx Tensors via Nx.stack HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nx.