Skip to content

Commit e709c64

Browse files
committed
PyTorch: Fix SGD ValueError
1 parent 042c11c commit e709c64

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

.github/workflow_scripts/build_pytorch.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ d2lbook build outputcheck tabcheck
2121
# Move aws copy commands for cache restore outside
2222
if [ "$DISABLE_CACHE" = "false" ]; then
2323
echo "Retrieving pytorch build cache from "$CACHE_DIR""
24-
measure_command_time "aws s3 sync s3://preview.d2l.ai/"$CACHE_DIR"/"$REPO_NAME"-"$TARGET_BRANCH"/_build/eval_pytorch _build/eval_pytorch --delete --quiet --exclude 'data/*'"
24+
measure_command_time "aws s3 sync s3://preview.d2l.ai/"$CACHE_DIR"/"$REPO_NAME"-"$TARGET_BRANCH"/_build/eval_pytorch/ _build/eval_pytorch/ --delete --quiet --exclude 'data/*'"
2525
echo "Retrieving pytorch slides cache from "$CACHE_DIR""
2626
aws s3 sync s3://preview.d2l.ai/"$CACHE_DIR"/"$REPO_NAME"-"$TARGET_BRANCH"/_build/slides _build/slides --delete --quiet --exclude 'data/*'
2727
fi

chapter_optimization/sgd.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def f_grad(x1, x2): # 目标函数的梯度
7575
def sgd(x1, x2, s1, s2, f_grad):
7676
g1, g2 = f_grad(x1, x2)
7777
# 模拟有噪声的梯度
78-
g1 += d2l.normal(0.0, 1, (1,))
79-
g2 += d2l.normal(0.0, 1, (1,))
78+
g1 += d2l.normal(0.0, 1, (1,)).item()
79+
g2 += d2l.normal(0.0, 1, (1,)).item()
8080
eta_t = eta * lr()
8181
return (x1 - eta_t * g1, x2 - eta_t * g2, 0, 0)
8282
```

0 commit comments

Comments
 (0)