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
0b2fa40d
Commit
0b2fa40d
authored
1 year ago
by
Matthias Reso
Browse files
Options
Downloads
Patches
Plain Diff
Add unit test for weight decay
parent
91e2573a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_finetuning.py
+31
-2
31 additions, 2 deletions
tests/test_finetuning.py
with
31 additions
and
2 deletions
tests/test_finetuning.py
+
31
−
2
View file @
0b2fa40d
# Copyright (c) Meta Platforms, Inc. and affiliates.
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
from
pytest
import
approx
from
unittest.mock
import
patch
from
unittest.mock
import
patch
import
importlib
from
torch.nn
import
Linear
from
torch.optim
import
AdamW
from
torch.utils.data.dataloader
import
DataLoader
from
torch.utils.data.dataloader
import
DataLoader
from
llama_recipes.finetuning
import
main
from
llama_recipes.finetuning
import
main
...
@@ -72,4 +74,31 @@ def test_finetuning_peft(step_lr, optimizer, get_peft_model, gen_peft_config, ge
...
@@ -72,4 +74,31 @@ def test_finetuning_peft(step_lr, optimizer, get_peft_model, gen_peft_config, ge
main
(
**
kwargs
)
main
(
**
kwargs
)
assert
get_peft_model
.
return_value
.
to
.
call_args
.
args
[
0
]
==
"
cuda
"
assert
get_peft_model
.
return_value
.
to
.
call_args
.
args
[
0
]
==
"
cuda
"
assert
get_peft_model
.
return_value
.
print_trainable_parameters
.
call_count
==
1
assert
get_peft_model
.
return_value
.
print_trainable_parameters
.
call_count
==
1
\ No newline at end of file
@patch
(
'
llama_recipes.finetuning.train
'
)
@patch
(
'
llama_recipes.finetuning.LlamaForCausalLM.from_pretrained
'
)
@patch
(
'
llama_recipes.finetuning.LlamaTokenizer.from_pretrained
'
)
@patch
(
'
llama_recipes.finetuning.get_preprocessed_dataset
'
)
@patch
(
'
llama_recipes.finetuning.get_peft_model
'
)
@patch
(
'
llama_recipes.finetuning.StepLR
'
)
def
test_finetuning_weight_decay
(
step_lr
,
get_peft_model
,
get_dataset
,
tokenizer
,
get_model
,
train
):
kwargs
=
{
"
weight_decay
"
:
0.01
}
get_dataset
.
return_value
=
[
1
]
get_peft_model
.
return_value
=
Linear
(
1
,
1
)
get_peft_model
.
return_value
.
print_trainable_parameters
=
lambda
:
None
main
(
**
kwargs
)
assert
train
.
call_count
==
1
args
,
kwargs
=
train
.
call_args
optimizer
=
args
[
4
]
print
(
optimizer
.
state_dict
())
assert
isinstance
(
optimizer
,
AdamW
)
assert
optimizer
.
state_dict
()[
"
param_groups
"
][
0
][
"
weight_decay
"
]
==
approx
(
0.01
)
\ 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