Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Llama Recipes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
meta-llama
Llama Recipes
Commits
f398bc54
Commit
f398bc54
authored
1 year ago
by
Matthias Reso
Browse files
Options
Downloads
Patches
Plain Diff
Added basic unit test for train method
parent
5b58afc7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_train_utils.py
+48
-0
48 additions, 0 deletions
tests/test_train_utils.py
with
48 additions
and
0 deletions
tests/test_train_utils.py
0 → 100644
+
48
−
0
View file @
f398bc54
import
torch
from
llama_recipes.utils.train_utils
import
train
def
test_gradient_accumulation
(
mocker
):
# import sys
# sys.path.append('/home/ubuntu/llama-recipes/')
model
=
mocker
.
MagicMock
(
name
=
"
model
"
)
model
().
loss
.
__truediv__
().
detach
.
return_value
=
torch
.
tensor
(
1
)
batch
=
{
"
input
"
:
torch
.
zeros
(
1
)}
train_dataloader
=
[
batch
,
batch
,
batch
,
batch
,
batch
]
eval_dataloader
=
None
tokenizer
=
mocker
.
MagicMock
()
optimizer
=
mocker
.
MagicMock
()
lr_scheduler
=
mocker
.
MagicMock
()
gradient_accumulation_steps
=
1
train_config
=
mocker
.
MagicMock
()
train_config
.
enable_fsdp
=
False
train_config
.
use_fp16
=
False
train_config
.
run_validation
=
False
train
(
model
,
train_dataloader
,
eval_dataloader
,
tokenizer
,
optimizer
,
lr_scheduler
,
gradient_accumulation_steps
,
train_config
,
)
assert
optimizer
.
zero_grad
.
call_count
==
5
optimizer
.
zero_grad
.
reset_mock
()
gradient_accumulation_steps
=
2
train
(
model
,
train_dataloader
,
eval_dataloader
,
tokenizer
,
optimizer
,
lr_scheduler
,
gradient_accumulation_steps
,
train_config
,
)
assert
optimizer
.
zero_grad
.
call_count
==
3
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment