# paddleslim.pantheon package

class `paddleslim.pantheon.``Teacher`(out_path=None, out_port=None)

  Bases: `object`

  The class defined for the teacher model. Generate knowledge data and transfer them to the student model.

  Parameters: | out_path (str|None) – The path to dump knowledge for offline mode. out_port (int|None) – The IP port number to send out knowledge for online mode, should be unique when launching multiple teachers in the same node.

  `dump`(knowledge)

    Dump one batch knowledge data into output file, only used in the offline mode.

    Parameters: | knowledge (dict) – The knowledge data to be dumped.

  `recv`()

    Recieve one data object from student.

    Returns: | The received data, can be any type of Python data object.

  `send`(data)

    Send one data object to student.

    Parameters: | data (Python data) – The data to be sent, can be any type of Python data object.

  `start`()

    Start teacher service, sychronize with student and launch the thread to monitor commands from student.

  `start_knowledge_service`(feed_list, schema, program, reader_config, exe, buf_size=10, times=1)

    Start the knowledge service to generate and transfer knowledge data. In GPU mode, the devices to execute knowledge prediction will be determined by environment variable FLAGS_selected_gpus, or by CUDA_VISIBLE_DEVICES if it is not set, and by CPU_NUM (default 1) in CPU mode. Only supported in static graph.

    Parameters: | feed_list (list) – A list of feed Variables or their names for the input program. schema (dict) – A dictionary to specify names and fetched Variables of knowledge. program (fluid.Program) – Inference program for the teacher model. reader_config (dict) – The config for data reader. Support all the three types of generators used by fluid.io.PyReader and fluid.io.DataLoader, and their configs contain the key-value pair of the generator type and a generator object, plus other necessary argument pairs. See the following: sample generator: reader_config={“sample_generator”: #some_sample_generator, “batch_size”: #batch_size, “drop_last”: #drop_last}, ‘drop_last’ set to True by default, sample list generator: reader_config={“sample_list_generator”: #some_sample_list_generator}, batch generator: reader_config={“batch_generator”: #some_batch_genrator}. The trial to parse config will be in the order of 1) -> 3), and any other unrelated keys in these configs will be ignored. exe (fluid.Executor) – The executor to run the input program. buf_size (int) – The size of buffers for data reader and knowledge writer on each device. times (int) – The maximum repeated serving times. Default 1. Whenever the public method ‘get_knowledge_generator()’ in Student object called once, the serving times will be added one, until reaching the maximum and ending the service. Only valid in online mode, and will be ignored in offline mode.

class `paddleslim.pantheon.``Student`(merge_strategy=None)

  Bases: `object`

  The class defined for the student model. Receive knowledge data from teacher model and carry out knowledge merging.

  Parameters: | merge_strategy (dict|None) – A dictionary whose keys are common schemas shared by different teachers, and each corresponding value specifies the merging strategy for different schemas respectively, supporting ‘sum’ and ‘mean’ now.

  `get_knowledge_desc`()

    Get description for knowledge, including shape, data type and lod level for each schema.

    Returns: | Knowledge description.
    Return type: | dict

  `get_knowledge_generator`(batch_size, drop_last=False)

    Get the generator for knowledge data, return None if last generator doesn’t finish yet.

    Parameters: | batch_size (int) – The batch size of returned knowledge data. drop_last (bool) – Whether to drop the last batch if its size is less than batch size.
    Returns: | The wrapper of knowledge data generator.
    Return type: | func

  `get_knowledge_qsize`()

    Get the real-time size of knowledge queue. If this size is denoted as qsize, it means that there are qsize batch knowledge data already pushed into knowledge queue and waiting for the knowledge generator to pop out. It’s dynamic and limited up to 100, the capacity of the knowledge queue.

    Returns: | The real-time size of knowledge queue.
    Return type: | int

  `recv`(teacher_id)

    Receive data from one teacher.

    Parameters: | teacher_id (int) – The id of teacher that receives data from.
    Returns: | The received data object.

  `register_teacher`(in_path=None, in_address=None)
    Register one teacher model and assign the order number to it as
      its id, with the file path (offline mode) or IP address (online mode) that the teacher model wrote knowledge data to.

    Parameters: | in_path (str|None) – The input file path. Default None. in_address (str|None) – The input IP address, in the format “<IP address>:<IP port>” (e.g. “127.0.0.1:8080”). Default None.

  `send`(data, teacher_ids=None)

    Send data to teachers.

    Parameters: | data – A Python data object. teacher_ids (list|None) – A list of teacher ids to send data. If set to None, send the data to all teachers. Default None.

  `start`()

    End teachers’ registration and synchronize with all of them.

## Submodules

## paddleslim.pantheon.student module

class `paddleslim.pantheon.student.``Student`(merge_strategy=None)

  Bases: `object`

  The class defined for the student model. Receive knowledge data from teacher model and carry out knowledge merging.

  Parameters: | merge_strategy (dict|None) – A dictionary whose keys are common schemas shared by different teachers, and each corresponding value specifies the merging strategy for different schemas respectively, supporting ‘sum’ and ‘mean’ now.

  `get_knowledge_desc`()

    Get description for knowledge, including shape, data type and lod level for each schema.

    Returns: | Knowledge description.
    Return type: | dict

  `get_knowledge_generator`(batch_size, drop_last=False)

    Get the generator for knowledge data, return None if last generator doesn’t finish yet.

    Parameters: | batch_size (int) – The batch size of returned knowledge data. drop_last (bool) – Whether to drop the last batch if its size is less than batch size.
    Returns: | The wrapper of knowledge data generator.
    Return type: | func

  `get_knowledge_qsize`()

    Get the real-time size of knowledge queue. If this size is denoted as qsize, it means that there are qsize batch knowledge data already pushed into knowledge queue and waiting for the knowledge generator to pop out. It’s dynamic and limited up to 100, the capacity of the knowledge queue.

    Returns: | The real-time size of knowledge queue.
    Return type: | int

  `recv`(teacher_id)

    Receive data from one teacher.

    Parameters: | teacher_id (int) – The id of teacher that receives data from.
    Returns: | The received data object.

  `register_teacher`(in_path=None, in_address=None)
    Register one teacher model and assign the order number to it as
      its id, with the file path (offline mode) or IP address (online mode) that the teacher model wrote knowledge data to.

    Parameters: | in_path (str|None) – The input file path. Default None. in_address (str|None) – The input IP address, in the format “<IP address>:<IP port>” (e.g. “127.0.0.1:8080”). Default None.

  `send`(data, teacher_ids=None)

    Send data to teachers.

    Parameters: | data – A Python data object. teacher_ids (list|None) – A list of teacher ids to send data. If set to None, send the data to all teachers. Default None.

  `start`()

    End teachers’ registration and synchronize with all of them.

## paddleslim.pantheon.teacher module

class `paddleslim.pantheon.teacher.``Teacher`(out_path=None, out_port=None)

  Bases: `object`

  The class defined for the teacher model. Generate knowledge data and transfer them to the student model.

  Parameters: | out_path (str|None) – The path to dump knowledge for offline mode. out_port (int|None) – The IP port number to send out knowledge for online mode, should be unique when launching multiple teachers in the same node.

  `dump`(knowledge)

    Dump one batch knowledge data into output file, only used in the offline mode.

    Parameters: | knowledge (dict) – The knowledge data to be dumped.

  `recv`()

    Recieve one data object from student.

    Returns: | The received data, can be any type of Python data object.

  `send`(data)

    Send one data object to student.

    Parameters: | data (Python data) – The data to be sent, can be any type of Python data object.

  `start`()

    Start teacher service, sychronize with student and launch the thread to monitor commands from student.

  `start_knowledge_service`(feed_list, schema, program, reader_config, exe, buf_size=10, times=1)

    Start the knowledge service to generate and transfer knowledge data. In GPU mode, the devices to execute knowledge prediction will be determined by environment variable FLAGS_selected_gpus, or by CUDA_VISIBLE_DEVICES if it is not set, and by CPU_NUM (default 1) in CPU mode. Only supported in static graph.

    Parameters: | feed_list (list) – A list of feed Variables or their names for the input program. schema (dict) – A dictionary to specify names and fetched Variables of knowledge. program (fluid.Program) – Inference program for the teacher model. reader_config (dict) – The config for data reader. Support all the three types of generators used by fluid.io.PyReader and fluid.io.DataLoader, and their configs contain the key-value pair of the generator type and a generator object, plus other necessary argument pairs. See the following: sample generator: reader_config={“sample_generator”: #some_sample_generator, “batch_size”: #batch_size, “drop_last”: #drop_last}, ‘drop_last’ set to True by default, sample list generator: reader_config={“sample_list_generator”: #some_sample_list_generator}, batch generator: reader_config={“batch_generator”: #some_batch_genrator}. The trial to parse config will be in the order of 1) -> 3), and any other unrelated keys in these configs will be ignored. exe (fluid.Executor) – The executor to run the input program. buf_size (int) – The size of buffers for data reader and knowledge writer on each device. times (int) – The maximum repeated serving times. Default 1. Whenever the public method ‘get_knowledge_generator()’ in Student object called once, the serving times will be added one, until reaching the maximum and ending the service. Only valid in online mode, and will be ignored in offline mode.

## paddleslim.pantheon.utils module

class `paddleslim.pantheon.utils.``EndSignal`

class `paddleslim.pantheon.utils.``StartSignal`

class `paddleslim.pantheon.utils.``SyncSignal`

`paddleslim.pantheon.utils.``check_ip`(address)

`paddleslim.pantheon.utils.``convert_dtype`(dtype)