Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
declearn2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Magnet
DecLearn
declearn2
Commits
d3e433b8
Verified
Commit
d3e433b8
authored
8 months ago
by
ANDREY Paul
Browse files
Options
Downloads
Patches
Plain Diff
Write unit tests for FairBatch controllers.
parent
b641e27a
No related branches found
No related tags found
1 merge request
!69
Enable Fairness-Aware Federated Learning
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/fairness/controllers/test_fairbatch_controllers.py
+80
-0
80 additions, 0 deletions
test/fairness/controllers/test_fairbatch_controllers.py
with
80 additions
and
0 deletions
test/fairness/controllers/test_fairbatch_controllers.py
0 → 100644
+
80
−
0
View file @
d3e433b8
# coding: utf-8
# Copyright 2023 Inria (Institut National de Recherche en Informatique
# et Automatique)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Unit tests for Fed-FairBatch controllers.
"""
import
os
from
unittest
import
mock
import
pytest
from
declearn.aggregator
import
Aggregator
,
SumAggregator
from
declearn.fairness.fairbatch
import
(
FairbatchControllerClient
,
FairbatchControllerServer
,
FairbatchDataset
,
)
from
declearn.test_utils
import
make_importable
with
make_importable
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))):
from
fairness_controllers_testing
import
(
FairnessControllerTestSuite
,
TOTAL_COUNTS
,
)
class
TestFairbatchControllers
(
FairnessControllerTestSuite
):
"""
Unit tests for Fed-FairBatch / FedFB controllers.
"""
server_cls
=
FairbatchControllerServer
client_cls
=
FairbatchControllerClient
def
setup_server_controller
(
self
)
->
FairbatchControllerServer
:
return
self
.
server_cls
(
f_type
=
"
equalized_odds
"
)
@pytest.mark.parametrize
(
"
use_secagg
"
,
[
False
,
True
],
ids
=
[
"
clrtxt
"
,
"
secagg
"
]
)
@pytest.mark.asyncio
async
def
test_finalize_fairness_setup
(
self
,
use_secagg
:
bool
,
)
->
None
:
aggregator
=
mock
.
create_autospec
(
Aggregator
,
instance
=
True
)
with
pytest
.
warns
(
RuntimeWarning
,
match
=
"
SumAggregator
"
):
agg_final
,
server
,
clients
=
(
await
self
.
run_finalize_fairness_setup
(
aggregator
,
use_secagg
)
)
# Verify that aggregators were replaced with a SumAggregator.
assert
isinstance
(
agg_final
,
SumAggregator
)
assert
all
(
isinstance
(
client
.
manager
.
aggrg
,
SumAggregator
)
for
client
in
clients
)
# Verify that the sampling controller was properly instantiated.
assert
isinstance
(
server
,
FairbatchControllerServer
)
assert
server
.
sampling_controller
.
counts
==
TOTAL_COUNTS
# Verify that FairBatch sampling probas were shared and applied.
probas
=
server
.
sampling_controller
.
get_sampling_probas
()
for
client
in
clients
:
dst
=
client
.
manager
.
train_data
assert
isinstance
(
dst
,
FairbatchDataset
)
total
=
sum
(
probas
[
group
]
for
group
in
dst
.
groups
)
expected
=
{
group
:
probas
[
group
]
/
total
for
group
in
dst
.
groups
}
assert
dst
.
get_sampling_probabilities
()
==
expected
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