-
Notifications
You must be signed in to change notification settings - Fork 95
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
Ability to clone neural nets instead of all the weights/biases tensors manually #568
Comments
What code did you use for cloning? |
@mratsim Like this: intoBrain.gru.w3s0 = ctx.variable(fromBrain.gru.w3s0.value.clone())
intoBrain.gru.w3sN = ctx.variable(fromBrain.gru.w3sN.value.clone())
intoBrain.gru.u3s = ctx.variable(fromBrain.gru.u3s.value.clone())
intoBrain.gru.bW3s = ctx.variable(fromBrain.gru.bW3s.value.clone())
intoBrain.gru.bU3s = ctx.variable(fromBrain.gru.bU3s.value.clone())
intoBrain.fc1.weight = ctx.variable(fromBrain.fc1.weight.value.clone())
intoBrain.fc1.bias = ctx.variable(fromBrain.fc1.bias.value.clone())
intoBrain.fc2.weight = ctx.variable(fromBrain.fc2.weight.value.clone())
intoBrain.fc2.bias = ctx.variable(fromBrain.fc2.bias.value.clone()) Where the brain is like this: CreatureBrain[T] = object
gru: GRULayer[T]
memory: Variable[Tensor[T]]
fc1: Linear[T]
fc2: Linear[T]
|
As a workaround in the meantime, you can use fields iterator here: https://nim-lang.org/docs/iterators.html#fields.i%2CS%2CT proc copyWeights[T](intoBrain: var T, fromBrain: T) =
for dst, src in fields(intoBrain, fromBrain):
when dst is Variable:
dst = ctx.variable(src.value.clone())
else:
dst.copyWeights(src) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right now have to manually clone all the weights, bug prone
The text was updated successfully, but these errors were encountered: