Skip to content

Documentation for Defaultmodelhandler Module

DefaultModelHandler

Bases: ModelHandler

Provides the initial default model.

This handler returns the baseline model with default weights, typically used at the start of the federation or when no suitable model offers have been received from peers.

Inherits from

ModelHandler: Provides the base interface for model operations.

Source code in nebula/core/situationalawareness/discovery/modelhandlers/defaultmodelhandler.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class DefaultModelHandler(ModelHandler):
    """
    Provides the initial default model.

    This handler returns the baseline model with default weights, 
    typically used at the start of the federation or when no suitable 
    model offers have been received from peers.

    Inherits from:
        ModelHandler: Provides the base interface for model operations.
    """

    def __init__(self):
        self.model = None
        self.rounds = 0
        self.round = 0
        self.epochs = 0
        self.model_lock = Locker(name="model_lock")
        self.params_lock = Locker(name="param_lock")
        self._nm: FederationConnector = None

    def set_config(self, config):
        """
        Args:
            config[0] -> total rounds
            config[1] -> current round
            config[2] -> epochs
            config[3] -> FederationConnector
        """
        self.params_lock.acquire()
        self.rounds = config[0]
        if config[1] > self.round:
            self.round = config[1]
        self.epochs = config[2]
        if not self._nm:
            self._nm = config[3]
        self.params_lock.release()

    def accept_model(self, model):
        return True

    async def get_model(self, model):
        """
        Returns:
            model with default weights
        """
        (sm, _, _) = await self._nm.engine.cm.propagator.get_model_information(None, "initialization", init=True)
        return (sm, self.rounds, self.round, self.epochs)

    def pre_process_model(self):
        """
        no pre-processing defined
        """
        pass

get_model(model) async

Returns:

Type Description

model with default weights

Source code in nebula/core/situationalawareness/discovery/modelhandlers/defaultmodelhandler.py
47
48
49
50
51
52
53
async def get_model(self, model):
    """
    Returns:
        model with default weights
    """
    (sm, _, _) = await self._nm.engine.cm.propagator.get_model_information(None, "initialization", init=True)
    return (sm, self.rounds, self.round, self.epochs)

pre_process_model()

no pre-processing defined

Source code in nebula/core/situationalawareness/discovery/modelhandlers/defaultmodelhandler.py
55
56
57
58
59
def pre_process_model(self):
    """
    no pre-processing defined
    """
    pass

set_config(config)

Source code in nebula/core/situationalawareness/discovery/modelhandlers/defaultmodelhandler.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def set_config(self, config):
    """
    Args:
        config[0] -> total rounds
        config[1] -> current round
        config[2] -> epochs
        config[3] -> FederationConnector
    """
    self.params_lock.acquire()
    self.rounds = config[0]
    if config[1] > self.round:
        self.round = config[1]
    self.epochs = config[2]
    if not self._nm:
        self._nm = config[3]
    self.params_lock.release()