Gradient Descent on Manifolds with VectorAdam
Sarina Li · Compiled from my original notes
This is a record of my experiments adapting VectorAdam for gradient-based optimization on a sphere. I explore why normalizing each update can lead to oscillation, how projecting gradients onto the tangent plane changes convergence, and the questions about momentum and parallel transport that followed. The notes below document the process, including approaches that did not work.
Optimizing on a Sphere
Sarina Li
Problem
Vector Adam, initially built on top of the ADAM optimization for neural networks has been observed to have issues with vectors. As a result, a variant (VectorAdam) was introduced.
Now imagine, let a and b be some arbitrary points on a sphere S. The goal is to use a variant of Vector Adam so that any arbitrary point n on the sphere can be optimized while staying on the sphere.
See the original VectorAdam paper done by my very smart, beautiful and awesome mentor Selena
Progress
May 22nd, 2024
I began this exploratory project on May 22nd 2024. I set up the repository and code environment. I also ran a couple runs of the initial VectorAdam demo code to understand what it was trying to do.
On this day, I also played around with the code and created a simulation using VectorAdam to optimize for the least distance between two points.
I noticed that the point would shoot out of the sphere, which is expected since with gradient descent, it will try to find the minimum by “descending” the gradient. However, we don’t want it to shoot out of the sphere.
May 29th, 2024
This week, I worked on a naïve solution for the optimization problem. Basically, I forcefully normalized the point that the VectorAdam would spit out to be on the sphere,
def normalize_tensor(tensor: torch.Tensor, radius: float):
magnitude = tensor.norm()
normalization_constant = radius / magnitude
normalized_tensor = normalization_constant * tensor
return normalized_tensorUsing this code, I could get the point to stay on the sphere. However, visually I noticed that upon entering a certain point, it would start oscillating between two points on the function. With the regular unnormalized point, the loss function slowly converges. So, now the issue is figuring out the root of the oscillation issue.
Here is a clearer video along with the loss function graphed (normalized and non-normalized)
I noticed that the oscillation takes places after the normalized point reaches a certain point. The next step is to try to pinpoint why the issue occurs. Here are my current (planned) approaches:
- Adjust the learning rate
- Perhaps this will reveal more about what is going on
- Understand the gradient more
- Investigate the pre and post normalization
June 7th, 2024
Adjusting Learning Rate
- After decreasing the learning rate to
0.1I found that the loss seemed to converge. However, You can see in earlier iterations there is some degree of oscillation

- Increasing the learning rate to
1.0intensified the oscillation. This was expected because the learning rate of0.5was already causing major oscillations.

June 16, 2024
Graphing the Gradient
Today I am going to try to graph the gradient at each step. This is going to be difficult because I will first have to understand what and how I can even graph this gradient. My hopes are I will be able to see visually what points on the gradient VectorAdam is getting stuck between on the sphere.
The first step is figuring out where the gradient is computed. This was the easy part, I found out that the gradient is computed in
loss1 = sphere_energy(a, b, v)
loss1.backward()and the .step() simply uses the gradient computed. After investigating further, I realize that the .grad attribute is just the optimal direction to move in. After looking around for a while, I realize that my understanding is wrong; I thought that the gradient was a vector field of which I could completely graph. This is incorrect because the gradient is actually just the vector that points to the steepest rate of change.
So, after this new understanding, I think I will have to approach the visualization in a different way, the actual vector may or may not be useful to see. As a result, I will be reapproaching this graphing issue in the coming days.
Projecting g1 and g2 onto the Sphere
For this step, I first had to understand what each step was doing to the two of these tensors. I also need to determine which of the two is the vector and which is the scalar so that I can correctly project the vector.
This is one of the first tries to implemented the improved version of the algorithm.

In this case, I noticed that the loss graph would drastically drop, then flatten out. This is better than before but not what I was looking for.
However, visually, the point did not end up as expected.

In hindsight, I realize now what I’m doing is projecting this point directly on the sphere. This doesn’t really make sense because that would modify the magnitude not the the actual direction which would matter for keeping the point on the sphere.
Another thing I thought I could do was move the operation of projecting onto the sphere.

However, unsurprisingly this didn’t work and caused the loss to be very erratic. This is likely because of two reasons: the first being projection onto the sphere didn’t even make sense (again just changing the magnitude would not fix the direction issue). The second problem is that the point on the actual sphere does not find the optimal spot between the two points.
June 24th, 2024
Today I am going to try to project the g1 vector onto the tangent sphere of the plane.
Here is my thought process:
- Get the normal vector
\vec{n}from the current point
- Get the output gradient vector of the VectorAdam algorithm
\vec{v}
- Find
proj_{\vec{n}}\vec{v}(the goal is to project\vec{v}onto the tangent plane of the current point)
- Find
\vec{v} - proj_{\vec{n}}{\vec{v}}and return it.

(0.5,0.5,0.5) and I am currently on point A, I want to project it onto the normal vector of A and then subtract that from the original gradient vector from VectorAdam producing a new vector, pointing A in the direction of B. Afterward, correction by normalizing onto the sphere is still required, I was initially concerned with the point on the tangent plane being really far off from the sphere (like in the picture) but it didn’t seem to pose as big of an issue as I initially thought.

This is an interesting shape of the loss graph (seen in the first one beside the sphere) as it converges, but not to the correct point. This will have to be investigated.
Second of all, you can see visually (the yellow point) that the point did not converge to the most optimal spot between the red and green dots on the sphere. This shows that something is still wrong with the algorithm.
# v is gr and n is cur_point. find the projection of v onto the tangent plane of n
dot_numerator = torch.dot(cur_point, gr)
dot_denominator = torch.dot(cur_point, cur_point)
proj_v_on_n = (dot_numerator / dot_denominator) * cur_point
proj_on_tangent_plane = gr - proj_v_on_n
p.data.sub_(proj_on_tangent_plane, alpha=lr)This was the code used to perform the steps stated above.
July 2nd, 2024
This week I have two things to try, the first is going to be correcting the place where I perform the projection onto the tangent plane. In my code, I was performing it after finding v_i and \vec{\widehat{m}}_i. This was causing issue with the accumulation of the gradients. So, I moved it up to before \vec{m}_i was even modified. After doing this, this is what the loss graph looked like:

UPDATE: I just realized I was performing operations on g1 in the code. This is a mistake since it is initially instantiated to be a 0 tensor.
July 16th, 2024
Sorry for no frequent updates!
Since last time, I realized (with guidance from Selena) that I was performing the projection in the wrong place in the VectorAdam algorithm. The step should take place before modifying g1 and g2 . I realized this after Selena pointed out that it did not make sense to try to perform the projection on the gradient it produces after since that would just negate the point of “accumulating” the difference that projection makes.
# v is gr and n is cur_point. find the projection of v onto the tangent plane of n
if project:
dot_numerator = torch.dot(cur_point, grad)
dot_denominator = torch.dot(cur_point, cur_point)
proj_v_on_n = (dot_numerator / dot_denominator) * cur_point
grad = grad - proj_v_on_n
g1.mul_(b1).add_(grad, alpha=1-b1)
if axis is not None:
dim = grad.shape[axis]
grad_norm = torch.norm(grad, dim=axis).unsqueeze(axis).repeat_interleave(dim, dim=axis)
grad_sq = grad_norm * grad_norm
g2.mul_(b2).add_(grad_sq, alpha=1-b2)
else:
g2.mul_(b2).add_(grad.square(), alpha=1-b2)After completing these changes, I immediately saw an improvement in the loss. Here is the loss graph for radius of 1. The left side will be the method using VectorAdam and projection, the right side will be the method using the original VectorAdam with forceful normalization onto the sphere.

Here are some detailed logs on the final position of the points:
The starting point is tensor([0., 0., 1.], dtype=torch.float64).
The two points a and b respectively are tensor([1., 0., 0.]) and tensor([0., 1., 0.])
The final position of projected VectorAdam is tensor([0.7071, 0.7071, 0.0007], requires_grad=True), the intended position is tensor([0.7071, 0.7071, 0.0000])
The final position of the unnormalized and unproject point is tensor([ 0.6316, 0.6316, -0.4498], requires_grad=True), the intended position is tensor([0.5000, 0.5000, 0.0000])It’s very cool to see that the final result of the projected result ends up almost exactly at the correct spot, the unprojected point has some trouble converging.
Another interesting observation is that upon trying different anchor points for the two points and different starting positions of the initial point, the loss graph almost looks identical. A possible reason is due to the fact the energy function is relatively simply. Since there aren’t many peaks and troughs, it may not be complex enough.
However, there is a clear improvement in the convergence.
So now, we should work on benchmarking. I will perform this in 3 distinct graphs:
- Make the radius of the sphere vary and overlay all of the loss lines. Then, show the average of the loss line.
- To do this without skewing the results, I will divide each of the individual losses by
r^2to ensure that the data is normalized.
- To do this without skewing the results, I will divide each of the individual losses by
- Graph the gradient vector at each step to show how the points move at each step.
- Perform this simulation for the projected and unprojected points.
July 23th, 2024
During this week, I mostly worked on benchmarking my work to show that there is a clear improvement. The two things I worked on were the following:
- Graph the gradient vector at each step
The purpose of this step is to see the general direction that the point takes at each step. For this, I used the ax.quiver functionality to show the vector in 3 dimensions. The way I graphed the vector was storing both the absolute position and the gradient vector. Then, I would show the vector that starts at the previous absolute position and in the direction of the gradient vector.
prev_vec = position_list[i-1]
new_vec = vector_list[i].detach().cpu().numpy()
ax.quiver(prev_vec[0], prev_vec[1], prev_vec[2], new_vec[0], new_vec[1], new_vec[2], color=color, normalize=False)Some drawbacks to this method is that I find the gradient vectors are quite large compared to the scale of the sphere. Because of that, I felt like the vectors provide no real value of seeing when the learning rate is considerably large.
Here is an image to demonstrate a sphere of radius 1 and having a learning process of 5 steps.

Another thing to note is that after the projection, the point is always normalized onto the sphere. This is what makes the actual point moving on the sphere coherent during the learning process visualization. I think there are a lot of issues with this visualization, I’m hoping there is a way to make this better.
- Graphing the loss at various radiuses
For this step, I chose to anchor a and b at points (1,0,0) and (0,1,0) respectively. Then, I chose the starting point n to be at (0, 0, 1) for all of the simulations.
I ran this simulation with 10 different radiuses from 1-10 and then I graphed the loss of each one and computed the average.
There are some interesting results to see, first here is an image of the graph:

Something interesting I noticed was that with the unprojected loss, even larger radiuses seem to converge.

Here you can observe that for a radius of 1, it does not seem to converge. Althought, this may be attributed to a large learning causing oscillation on the gradient.
Overall, I think I can say that I conclude the projected algorithm seems to converge faster than the unprojected algorithm. We can see that at about 10 steps, the blue line has already reached the minimum loss it can obtain with this energy function whereas the green is still oscillating.
So, projecting the gradient vector does improve VectorAdam.
July 29th, 2024


m1 = g1 / (1-(b1**state["step"]))
# project m1 onto grad
dot_numerator = torch.dot(m1, grad)
dot_denominator = torch.dot(grad, grad)
m1 = (dot_numerator / dot_denominator) * m1

This figure contains the projection of the momentum as well as the gradient.
Possible Reasons Why Projecting the Momentum is Better
- accumulating the previous gradients, acting like the “momentum” of the descent
- perhaps during the start there is a small “spike” because of adding the vectors from the overshooting the point and from the initial start point (different directions basically) then when accumulated it causes that strange spike
Plan of action on how to prove hypothesis
- check the gradient vector at each step for steps 1-5 (most relevant to the spike)
- compare the gradient for each (momentum projected vs momentum not projected)








- noticed that the momentum vector when unprojected points away from the desired spot. Could be an issue because it causes the point to overshoot the desired position.
from this itr onward, the red point (without momentum projected) will move towards the desired position.
the corresponding momentum vectors at each itr:
Sept 29, 2024
So what’s next? What will I be working on after?
- Extending this to more than just spheres, can this be applied to any manifold?
- Can we implement parallel transport with the current momentum vector?
- What applications can we apply this to in order to improve the performance/solve new problems?
The first step is to read about parallel transport. Embarrassingly, I know nothing about this and I will be reading a series of textbooks to inform myself about the general ideas. The step after that is deciding how to use the analytical formula for parallel transport and how it could apply to a sphere. Then, it would be actually implementing the code.
Parallel Transport
Sarina Li
Problem
Based on the new modifications of VectorAdam, the momentum vector can be moved along the sphere using parallel transport due to the momentum being projected completely out for larger learning rates.
Additionally, can this algorithm be applied to more than just spheres? What about ellipsoids? What about manifolds in general?
To address these problems, I’ll be documenting my work here