You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

t_trainer.rst 8.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. .. _trainer:
  2. AutoGL Trainer
  3. ==============
  4. AutoGL project use ``trainer`` to handle the auto-training of tasks. Currently, we support the following tasks:
  5. * ``NodeClassificationTrainer`` for semi-supervised node classification
  6. * ``GraphClassificationTrainer`` for supervised graph classification
  7. * ``LinkPredictionTrainer`` for link prediction
  8. Lazy Initialization
  9. -------------------
  10. Similar reason to :ref:model, we also use lazy initialization for all trainers. Only (part of) the hyper-parameters will be set when ``__init__()`` is called. The ``trainer`` will have its core ``model`` only after ``initialize()`` is explicitly called, which will be done automatically in ``solver`` and ``duplicate_from_hyper_parameter()``, after all the hyper-parameters are set properly.
  11. Train and Predict
  12. -----------------
  13. After initializing a trainer, you can train it on the given datasets.
  14. We have given the training and testing functions for the tasks of node classification, graph classification, and link prediction up to now. You can also create your tasks following the similar patterns with ours. For training, you need to define ``train_only()`` and use it in ``train()``. For testing, you need to define ``predict_proba()`` and use it in ``predict()``.
  15. The evaluation function is defined in ``evaluate()``, you can use your our evaluation metrics and methods.
  16. Node Classification with Sampling
  17. ---------------------------------
  18. According to various present studies, training with spatial sampling has been demonstrated
  19. as an efficient technique for representation learning on large-scale graph.
  20. We provide implementations for various representative sampling mechanisms including
  21. Neighbor Sampling, Layer Dependent Importance Sampling (LADIES), and GraphSAINT.
  22. With the leverage of various efficient sampling mechanisms,
  23. users can utilize this library on large-scale graph dataset, e.g. Reddit.
  24. Specifically, as various sampling techniques generally require model to support
  25. some layer-wise processing in forwarding, now only the provided GCN and GraphSAGE models are ready for
  26. Node-wise Sampling (Neighbor Sampling) and Layer-wise Sampling (LADIES).
  27. More models and more tasks are scheduled to support sampling in future version.
  28. * Node-wise Sampling (GraphSAGE)
  29. Both ``GCN`` and ``GraphSAGE`` models are supported.
  30. * Layer-wise Sampling (Layer Dependent Importance Sampling)
  31. Only the ``GCN`` model is supported in current version.
  32. * Subgraph-wise Sampling (GraphSAINT)
  33. As The GraphSAINT sampling technique have no specific requirements for model to adopt,
  34. most of the available models are feasible for adopting GraphSAINT technique.
  35. However, the prediction process is a potential bottleneck or even obstacle
  36. when the GraphSAINT technique is actually applied on large-scale graph,
  37. thus the the model to adopt is better to support layer-wise prediction,
  38. and the provided ``GCN`` model already meet that enhanced requirement.
  39. According to empirical experiments,
  40. the implementation of GraphSAINT now has the leverage to support
  41. an integral graph smaller than the *Flickr* graph data.
  42. The sampling techniques can be utilized by adopting corresponding trainer
  43. ``NodeClassificationGraphSAINTTrainer``,
  44. ``NodeClassificationLayerDependentImportanceSamplingTrainer``,
  45. and ``NodeClassificationNeighborSamplingTrainer``.
  46. You can either specify the corresponding name of trainer in YAML configuration file
  47. or instantiate the solver ``AutoNodeClassifier``
  48. with the instance of specific trainer. However, please make sure to manange some key
  49. hyper-paramters properly inside the hyper-parameter space. Specifically:
  50. For ``NodeClassificationLayerDependentImportanceSamplingTrainer``, you need to set the
  51. hyper-parameter ``sampled_node_sizes`` properly. The space of ``sampled_node_sizes`` should
  52. be a list of the same size with your **Sequential Model**. For example, if you have a
  53. model with layer number 4, you need to pass the hyper-parameter space properly:
  54. .. code-block:: python
  55. solver = AutoNodeClassifier(
  56. graph_models=(A_MODEL_WITH_4_LAYERS,),
  57. default_trainer='NodeClassificationLayerDependentImportanceSamplingTrainer',
  58. trainer_hp_space=[
  59. # (required) you need to set the trainer_hp_space properly.
  60. {
  61. 'parameterName': 'sampled_node_sizes',
  62. 'type': 'NUMERICAL_LIST',
  63. "numericalType": "INTEGER",
  64. "length": 4, # same with the layer number of your model
  65. "minValue": [200,200,200,200],
  66. "maxValue": [1000,1000,1000,1000],
  67. "scalingType": "LOG"
  68. },
  69. ...
  70. ]
  71. )
  72. If the layer number of your model is a searchable hyper-parameters, you can also set the ``cutPara``
  73. and ``cutFunc`` properly, to make it connected with your layer number hyper-parameters of model.
  74. .. code-block:: python
  75. '''
  76. Suppose the layer number of your model is of the following forms:
  77. {
  78. 'parameterName': 'layer_number',
  79. 'type': 'INTEGER',
  80. 'minValue': 2,
  81. 'maxValue': 4,
  82. 'scalingType': 'LOG'
  83. }
  84. '''
  85. solver = AutoNodeClassifier(
  86. graph_models=(A_MODEL_WITH_DYNAMIC_LAYERS,),
  87. default_trainer='NodeClassificationLayerDependentImportanceSamplingTrainer',
  88. trainer_hp_space=[
  89. # (required) you need to set the trainer_hp_space properly.
  90. {
  91. 'parameterName': 'sampled_node_sizes',
  92. 'type': 'NUMERICAL_LIST',
  93. "numericalType": "INTEGER",
  94. "length": 4, # max length
  95. "cutPara": ("layer_number", ), # link with layer_number
  96. "cutFunc": lambda x:x[0], # link with layer_number
  97. "minValue": [200,200,200,200],
  98. "maxValue": [1000,1000,1000,1000],
  99. "scalingType": "LOG"
  100. },
  101. ...
  102. ]
  103. )
  104. Similarly, if you want to use ``NodeClassificationNeighborSamplingTrainer``, you need to
  105. make sure setting the hyper-parameter ``sampling_sizes`` the same length as the layer number
  106. of your model. For example:
  107. .. code-block:: python
  108. '''
  109. Suppose the layer number of your model is of the following forms:
  110. {
  111. 'parameterName': 'layer_number',
  112. 'type': 'INTEGER',
  113. 'minValue': 2,
  114. 'maxValue': 4,
  115. 'scalingType': 'LOG'
  116. }
  117. '''
  118. solver = AutoNodeClassifier(
  119. graph_models=(A_MODEL_WITH_DYNAMIC_LAYERS,),
  120. default_trainer='NodeClassificationNeighborSamplingTrainer',
  121. trainer_hp_space=[
  122. # (required) you need to set the trainer_hp_space properly.
  123. {
  124. 'parameterName': 'sampling_sizes',
  125. 'type': 'NUMERICAL_LIST',
  126. "numericalType": "INTEGER",
  127. "length": 4, # max length
  128. "cutPara": ("layer_number", ), # link with layer_number
  129. "cutFunc": lambda x:x[0], # link with layer_number
  130. "minValue": [20,20,20,20],
  131. "maxValue": [100,100,100,100],
  132. "scalingType": "LOG"
  133. },
  134. ...
  135. ]
  136. )
  137. You can also pass a trainer inside model list directly. A brief example is demonstrated as follows:
  138. .. code-block:: python
  139. ladies_sampling_trainer = NodeClassificationLayerDependentImportanceSamplingTrainer(
  140. model='gcn', num_features=dataset.num_features, num_classes=dataset.num_classes, ...
  141. )
  142. ladies_sampling_trainer.hyper_parameter_space = [
  143. # (required) you need to set the trainer_hp_space properly.
  144. {
  145. 'parameterName': 'sampled_node_sizes',
  146. 'type': 'NUMERICAL_LIST',
  147. "numericalType": "INTEGER",
  148. "length": 4, # max length
  149. "cutPara": ("num_layers", ), # link with layer_number
  150. "cutFunc": lambda x:x[0], # link with layer_number
  151. "minValue": [200,200,200,200],
  152. "maxValue": [1000,1000,1000,1000],
  153. "scalingType": "LOG"
  154. },
  155. ...
  156. ]
  157. AutoNodeClassifier(graph_models=(ladies_sampling_trainer,), ...)