FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
docker-python/tests/test_transformers.py at master · AIComputerVision/docker-python · GitHub
AIComputerVision
/
docker-python
Public
forked from
Kaggle/docker-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
docker-python
/
tests
/
test_transformers.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
25 lines (21 loc) · 929 Bytes
Breadcrumbs
docker-python
/
tests
/
test_transformers.py
Copy path
File metadata and controls
25 lines (21 loc) · 929 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import
unittest
import
torch
from
transformers
import
AdamW
class
TestTransformers
(
unittest
.
TestCase
):
def
assertListAlmostEqual
(
self
,
list1
,
list2
,
tol
):
self
.
assertEqual
(
len
(
list1
),
len
(
list2
))
for
a
,
b
in
zip
(
list1
,
list2
):
self
.
assertAlmostEqual
(
a
,
b
,
delta
=
tol
)
def
test_adam_w
(
self
):
w
=
torch
.
tensor
([
0.1
,
-
0.2
,
-
0.1
],
requires_grad
=
True
)
target
=
torch
.
tensor
([
0.4
,
0.2
,
-
0.5
])
criterion
=
torch
.
nn
.
MSELoss
()
# No warmup, constant schedule, no gradient clipping
optimizer
=
AdamW
(
params
=
[
w
],
lr
=
2e-1
,
weight_decay
=
0.0
)
for
_
in
range
(
100
):
loss
=
criterion
(
w
,
target
)
loss
.
backward
()
optimizer
.
step
()
w
.
grad
.
detach_
()
# No zero_grad() function on simple tensors. we do it ourselves.
w
.
grad
.
zero_
()
self
.
assertListAlmostEqual
(
w
.
tolist
(), [
0.4
,
0.2
,
-
0.5
],
tol
=
1e-2
)
Back
|
FazBrowse Home
|
New Git URL