Unverified Commit e0f0fa2a authored by Da Zheng's avatar Da Zheng Committed by GitHub
Browse files

Fix a bug in sparse optimizer. (#3779)



* fix a bug.

* Update pylintrc

* fix.
Co-authored-by: default avatarQuan (Andy) Gan <coin2028@hotmail.com>
parent 3521fbe9
...@@ -48,11 +48,16 @@ class DistSparseGradOptimizer(abc.ABC): ...@@ -48,11 +48,16 @@ class DistSparseGradOptimizer(abc.ABC):
for emb in self._params: for emb in self._params:
name = emb._tensor.name name = emb._tensor.name
kvstore = emb._tensor.kvstore kvstore = emb._tensor.kvstore
trace = emb._trace
trainers_per_server = self._world_size // kvstore.num_servers trainers_per_server = self._world_size // kvstore.num_servers
idics = [t[0] for t in trace] idics = []
grads = [t[1].grad.data for t in trace] grads = []
for trace in emb._trace:
if trace[1].grad is not None:
idics.append(trace[0])
grads.append(trace[1].grad.data)
else:
assert len(trace[0]) == 0
# If the sparse embedding is not used in the previous forward step # If the sparse embedding is not used in the previous forward step
# The idx and grad will be empty, initialize them as empty tensors to # The idx and grad will be empty, initialize them as empty tensors to
# avoid crashing the optimizer step logic. # avoid crashing the optimizer step logic.
......
...@@ -200,6 +200,9 @@ function-naming-style=snake_case ...@@ -200,6 +200,9 @@ function-naming-style=snake_case
# f - files # f - files
# i, j, k - loop variables # i, j, k - loop variables
# u, v, e - nodes and edges # u, v, e - nodes and edges
# s, d - source and destination
# t - time
# r - relation type
# n, m - general integers representing quantity # n, m - general integers representing quantity
# w, x, y, z - general math variables # w, x, y, z - general math variables
# g, G - graphs # g, G - graphs
...@@ -210,7 +213,7 @@ function-naming-style=snake_case ...@@ -210,7 +213,7 @@ function-naming-style=snake_case
# op - operators # op - operators
# ty - type # ty - type
# A, B, C, W - for tensor operators like matmul # A, B, C, W - for tensor operators like matmul
good-names=f,i,j,k,u,v,e,n,m,w,x,y,z,g,G,hg,sg,fn,ex,Run,_,us,vs,gs,es,op,ty,A,B,C,W,a,b,N,D1,D2,R good-names=f,i,j,k,u,v,e,n,m,w,x,y,z,s,d,t,r,g,G,hg,sg,fn,ex,Run,_,us,vs,gs,es,op,ty,A,B,C,W,a,b,N,D1,D2,R
# Include a hint for the correct naming format with invalid-name. # Include a hint for the correct naming format with invalid-name.
include-naming-hint=no include-naming-hint=no
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment