Comments (5)
Hmmm. It works as I had expected it to do.
Here's my repro:
[Fact]
public void Validate_1187()
{
var target = 1.5f;
using var h = torch.rand(10);
using var expected = h.clone();
// This should do nothing, including blow up.
h[h > target] = 1.0f;
Assert.Equal(expected, h);
}
What was your expected result?
from torchsharp.
Ok Niklas got the solution:
h[h > target] = h[h > target] .copy_(1);
The problem arises when the h[h > target] has zero length or is null. (Think......)
Thanks Niklas
The goal of the hole script us to get the first non-zero of the row and when hot-encode it. Whats for labeling for stock market data. I have an LLM Encoder with next step prediction self-subervised training. I want fine-tune as follows profit - neutral - stop loss.
Something like this:
from:
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 2 0 0 0 0 0 0
0 0 0 1 1 1 2 0 0 0 0 0 0 0
0 0 0 1 1 2 0 0 0 0 0 0 0 0
0 0 1 1 2 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 2 2 1
0 0 0 0 2 2 0 0 0 2 2 2 1 1
0 0 0 2 2 0 0 0 2 2 2 2 2 1
0 0 0 0 0 0 0 0 0 2 2 0 2 2
to:
1 0 0
0 1 0
0 1 0
0 1 0
0 1 0
1 0 0
0 0 1
0 0 1
0 0 1
0 0 1
I use Rhino3d as visualization for tensors.....
from torchsharp.
Is the behavior different from PyTorch? If the assignment is supposed to do what your workaround does, can you give me a simple example in Python that illustrates it?
from torchsharp.
It is a custom made code. All c#. So i cannot say. I have also a runtime-compiler plugin in the CAD-System which is compiling a vs-project and serializes it before. (So you do not to need to restart the programm - something what if you attach an dll in VS-Code does not work) So where can be a series of problems. I changed from
h[h > target] = 1.0f; to h[h > target] = h[h > target].copy_(1);
All tensors in cuda. Where is the spagetti-monster code for what task:
private Tensor LabelEncoder(Tensor bar, double target, int steps)
{
//Risk-Reward 1:1
//bar Sequence -- Open|H|L|C|WAP|Volume|Ratio|YearMonthDay|HourMinutesSeconds
Func<Tensor, int, int,Tensor> hotselect = (x, dim, label) =>
{
var max = torch.max(x != 0, dim: dim).indexes;
max = max + arange(x.numel() / x.size(dim), dtype: ScalarType.Int64, device: x.device) * x.size(dim);
max = torch.nn.functional.one_hot(x.flatten()[max].to(ScalarType.Int64), label);
var n0 = max[.., 0];
var n1 = max[.., 1];
max[.., 0] = n1;
max[.., 1] = n0;
return max;
};
int high = 1;
int low = 2;
int close = 3;
var v = bar.clone();
v = v.unsqueeze(0);
v = v.unfold(dimension: 1, size: steps, step: 1)[0, .., .., ..].permute(0, 2, 1);
//[1269674x15x9]
var h = (v[.., 1.., high].permute(1, 0) / v[.., 0, close]).permute(1, 0) - 1.0;
h[h > target] = h[h > target].copy(1);
h[h != 1] = h[h != 1].copy(0);
var l = ((v[.., 1.., low].permute(1, 0) / v[.., 0, close]).permute(1, 0) - 1.0) * -1.0;
l[l > target] = l[l > target].copy( 1);
l[l != 1] = l[l != 1].copy(0);
var mix = torch.zeros_like(h, device: bar.device);
mix[(l == 1)] = mix[(l == 1)].copy_(1);
mix[(h == 1)] = mix[(h == 1)].copy_(2);
var sum = mix.sum(1);
var idx = hotselect(mix, 1, 3);
var extend = torch.zeros(new long[] { steps - 1, 3 }, dtype: idx.dtype, device: idx.device);
extend[.., 1] = 1.0;
idx = torch.cat(new List() { idx, extend }, dim: 0L);
return idx;
}
from torchsharp.
I cannot reproduce the error... no idea. Sorry. The mistake was some where else.
from torchsharp.
Related Issues (20)
- Module.to should not be differentiable HOT 3
- Compute jacobian HOT 5
- Issue with exportsd.py for optimizers when no state has been calculated
- mu_product in NAdam optimizer is never initialized HOT 1
- Add an option to dispose of Distributions / let it's Tensor parameters optionally be moved to wrapping dispose container HOT 5
- Setting .bias on nn.Linear crashes HOT 4
- Calling `pad_packed_sequence` with tensors on cuda and `enforce_sorted=false` causes issue
- `optim.LoadStateDict` from existing StateDict doesn't clone tensors HOT 1
- `Tensor.Load` when tensor is on CUDA fails
- Conditional load tensors in Optimizers aren't loaded onto the correct device HOT 1
- DirectML Support HOT 1
- Module.to doesn't transfer parameters in `ParameterList` or `ParameterDict` HOT 1
- `Module.to(ScalarType)` has restrictions in `PyTorch` which aren't restricted in `TorchSharp` HOT 1
- Incomplete transfer of module to device (only with 0.101.3) HOT 36
- MissingMethodException when trying to declare a resnet18 model HOT 1
- MissingMethodException HOT 5
- Having trouble moving a module from one GPU to another. HOT 22
- Using skipfc: true with resnet model doesn't appear to remove the fully connected layer HOT 9
- Unable to use torch.Generator on CUDA HOT 2
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 torchsharp.