Comments (2)
This used to be a design choice before we introduced NonTensorData
Context
We initially thought it could be interesting to let tensorclass carry non-tensor data, but thought it was better to exclude it from the keys since things like apply
or even any other op that iterates through the keys (reshape
, gather
, ...) would have been meaningless with non-tensor data.
Then we introduces the NonTensorData
which is a simple subclass of the a tensorclass that can only carry non-tensor data. If you call tensordict.keys(include_nested=True)
you will have a NonTensorData
node appearing as if it had no leaves, but in reality it is a leaf. If you call apply
over NonTensorData it's ok because it does not access the data
field (it's not part of the keys). But becaue we hack through __getitem__
and __setitem__
to access NonTensorData.data
, the situation is less clear (one would imagine that the non-tensor data is now part of the keys since we use the key to set or access the value).
Solution
We introduced a is_leaf
function in keys, items, values and apply to quickly check if a node is a leaf or not. That allows us to avoid things like reshape
to access the non-tensor data thinking it's a leaf while still presenting non-tensor data as leaves to the user.
We should now apply something similar with all tensorclasses: by default, keys
will return all the data (tensor and non-tensor) but internally operations will only be applied to tensor-data.
from tensordict.
Sounds good to me!
If I understand it correctly then 'real' leafs are tensors and non-tensors are not leafs because they're wrapped in NonTensorData, which is a dataclass-subclass?
As a user, I'd find that slightly confusing, since to me non-tensor data does appear as leafs. But I guess the is_leaf
is only an internal implementation details?
from tensordict.
Related Issues (20)
- [BUG] pad_sequence raises an error when return_mask=True HOT 1
- [BUG] Bad Index Behavior after indexing an expanded tensordict HOT 2
- [Feature Request] Docs don't mention how to install tensordict / that it's a seperate package from torch
- Why is Tensorclass implemented as a decorator? HOT 3
- [BUG] Functional call with TensorDictParams is slow HOT 1
- [BUG] I think TensorDict doesn't work with pin_memory in a dataloader HOT 3
- [BUG] Cannot override __getitem__ or __setitem__ for tensorclass with non-tensor data HOT 6
- Torch nested tensor, support for mean along the ragged dimension HOT 2
- [BUG] @tensorclass.to_dict() removes non-tensor entries. HOT 2
- [BUG] missing dependency "packaging" HOT 1
- [BUG] Wrong values in TensorDict with device="cpu" specified HOT 9
- [Feature Request] Using `pad_sequence(... return_mask=True)` leads to confusing debug sessions HOT 7
- [BUG] tensordict.TensorDict and tensordict.nn.make_tensordict can't handle dictionaries with non-string keys HOT 4
- [BUG] Out of date pip install for python 3.12 / Ubuntu 24.04 LTS HOT 3
- [BUG] `tensordict.pad_sequence` with a `tensorclass` returns `TensorDict` HOT 5
- No fallback when `ftdim` dependency is missing
- [BUG] `tensordict.pad_sequence` silently ignores non-tensor attributes in `tensorclass`es or `TensorDict`s HOT 6
- [Bug] TensorDict `gather` method not preserving `device` attribute
- [BUG] @property setter fails with tensorclass
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 tensordict.