Comments (3)
Paramters generally should not be directly changed in the forward pass. For best practise, you may use self.register_buffer instead.
Anyway, if you really want to change the data in a parameter, use the following code:
def forward(self, x: torch.Tensor) -> torch.Tensor:
n_tokens = x.size(1)
with torch.no_grad():
self.cache.data = torch.roll(self.cache, -n_tokens, dims=1)
self.cache[:, -n_tokens:, :] = x
return self.cache
By the way, I'm not sure what you want to do with MyModule(torch.zeros(2, 3, 4))(torch.zeros(2, 2, 4))
. Generally the returned tensor/parameter cannot be called.
from pytorch.
This seems to be the expected behavior, you would expect an out of place op on a Parameter (e.g. torch.roll
) to return a tensor
, and you attempt to reassign this to self.cache, which fails with the expected error message
from pytorch.
Thank you for your reply. As you mentioned, register_buffer
might be the correct way to go.
The goal of the cache is to append historical elements alongside the current tensor.
from pytorch.
Related Issues (20)
- The empty 0D or more D tensor with exceeding `dim`(`dim=100` or `dim=-100`) for `cummin()` works
- The empty 0D or more D tensor with exceeding `dim`(`dim=100` or `dim=-100`) for `cummax()` works HOT 1
- Failing to export ONNX when `GroupNorm` input shape = 2 HOT 1
- The shape of weights in lstm seems to be wrong. HOT 1
- `input` argument of `nan_to_num()` works with `complex` type but `nan`, `posinf` and `neginf` argument don't work with `complex` type
- torch cuda-121 fails to load .so library HOT 2
- MPS and cpu method results are drastically different HOT 13
- [OpenMP] Unlimited number of threads are spawned. HOT 6
- Poor scaling of `torch.masked.mean` HOT 1
- compiling outer function uses much more memory than compiling inner function when there is bit-packing
- RuntimeError: The size of tensor a (8) must match the size of tensor b (2744) at non-singleton dimension 1 HOT 1
- Pytorch nightly 7/21 version doesn't have python3.11 support HOT 1
- DISABLED test_trigger_bisect_on_error (__main__.ExcTests) HOT 1
- allow tuples as keys for ModuleDict
- When will flash attention3 be integrated HOT 2
- Pytorch Error: ImportError: /home/dp/anaconda3/envs/ComfyUI/lib/python3.11/site-packages/torch/lib/../../nvidia/cusparse/lib/libcusparse.so.12: undefined symbol: __nvJitLinkComplete_12_4, version libnvJitLink.so.12 HOT 1
- How to create a custom op which can be compile by dynamo inductor? HOT 3
- SDPA + compile + bfloat16 fails (ROCm) HOT 4
- RuntimeError: INTERNAL ASSERT FAILED at "../aten/src/ATen/native/sparse/SparseCsrTensorMath.cpp":1306 HOT 1
- RuntimeError: false INTERNAL ASSERT FAILED at "../aten/src/ATen/native/BatchLinearAlgebra.cpp":498 HOT 1
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 pytorch.