autora.theorist.darts.model_search
Cell
Bases: Module
A cell as defined in differentiable architecture search. A single cell corresponds to a computation graph with the number of input nodes defined by n_input_states and the number of hidden nodes defined by steps. Input nodes only project to hidden nodes and hidden nodes project to each other with an acyclic connectivity pattern. The output of a cell corresponds to the concatenation of all hidden nodes. Hidden nodes are computed by integrating transformed outputs from sending nodes. Outputs from sending nodes correspond to mixture operations, i.e. a weighted combination of pre-specified operations applied to the variable specified by the sending node (see MixedOp).
Attributes:
Name | Type | Description |
---|---|---|
_steps |
number of hidden nodes |
|
_n_input_states |
number of input nodes |
|
_ops |
list of mixture operations (amounts to the list of edges in the cell) |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
__init__(steps=2, n_input_states=1, primitives=PRIMITIVES)
Initializes a cell based on the number of hidden nodes (steps) and the number of input nodes (n_input_states).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
steps
|
int
|
number of hidden nodes |
2
|
n_input_states
|
int
|
number of input nodes |
1
|
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
forward(input_states, weights)
Computes the output of a cell given a list of input states (variables represented in input nodes) and a weight matrix specifying the weights of each operation for each edge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_states
|
List
|
list of input nodes |
required |
weights
|
Tensor
|
matrix specifying architecture weights, i.e. the weights associated with each operation for each edge |
required |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
DARTSType
Bases: str
, Enum
Enumerator that indexes different variants of DARTS.
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
22 23 24 25 26 27 28 29 30 31 32 |
|
MixedOp
Bases: Module
Mixture operation as applied in Differentiable Architecture Search (DARTS). A mixture operation amounts to a weighted mixture of a pre-defined set of operations that is applied to an input variable.
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
__init__(primitives=PRIMITIVES)
Initializes a mixture operation based on a pre-specified set of primitive operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
primitives
|
Sequence[str]
|
list of primitives to be used in the mixture operation |
PRIMITIVES
|
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
forward(x, weights)
Computes a mixture operation as a weighted sum of all primitive operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
input to the mixture operations |
required |
weights
|
Tensor
|
weight vector containing the weights associated with each operation |
required |
Returns:
Name | Type | Description |
---|---|---|
y |
float
|
result of the weighted mixture operation |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
Network
Bases: Module
A PyTorch computation graph according to DARTS. It consists of a single computation cell which transforms an input vector (containing all input variable) into an output vector, by applying a set of mixture operations which are defined by the architecture weights (labeled "alphas" of the network).
The network flow looks as follows: An input vector (with _n_input_states elements) is split into _n_input_states separate input nodes (one node per element). The input nodes are then passed through a computation cell with _steps hidden nodes (see Cell). The output of the computation cell corresponds to the concatenation of its hidden nodes (a single vector). The final output corresponds to a (trained) affine transformation of this concatenation (labeled "classifier").
Attributes:
Name | Type | Description |
---|---|---|
_n_input_states |
length of input vector (translates to number of input nodes) |
|
_num_classes |
length of output vector |
|
_criterion |
optimization criterion used to define the loss |
|
_steps |
number of hidden nodes in the cell |
|
_architecture_fixed |
specifies whether the architecture weights shall remain fixed (not trained) |
|
_classifier_weight_decay |
a weight decay applied to the classifier |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
|
__init__(num_classes, criterion, steps=2, n_input_states=2, architecture_fixed=False, train_classifier_coefficients=False, train_classifier_bias=False, classifier_weight_decay=0, darts_type=DARTSType.ORIGINAL, primitives=PRIMITIVES)
Initializes the network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_classes
|
int
|
length of output vector |
required |
criterion
|
Callable
|
optimization criterion used to define the loss |
required |
steps
|
int
|
number of hidden nodes in the cell |
2
|
n_input_states
|
int
|
length of input vector (translates to number of input nodes) |
2
|
architecture_fixed
|
bool
|
specifies whether the architecture weights shall remain fixed |
False
|
train_classifier_coefficients
|
bool
|
specifies whether the classifier coefficients shall be trained |
False
|
train_classifier_bias
|
bool
|
specifies whether the classifier bias shall be trained |
False
|
classifier_weight_decay
|
float
|
a weight decay applied to the classifier |
0
|
darts_type
|
DARTSType
|
variant of DARTS (regular or fair) that is applied for training |
ORIGINAL
|
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
apply_weight_decay_to_classifier(lr)
Applies a weight decay to the weights projecting from the cell to the final output layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lr
|
float
|
learning rate |
required |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
arch_parameters()
Returns architecture weights.
Returns:
Name | Type | Description |
---|---|---|
_arch_parameters |
List
|
architecture weights. |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
393 394 395 396 397 398 399 400 |
|
architecture_to_str_list(input_labels, output_labels, output_function_label='', decimals_to_display=2, output_format='console')
Returns a list of strings representing the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_labels
|
Sequence[str]
|
list of strings representing the input states. |
required |
output_labels
|
Sequence[str]
|
list of strings representing the output states. |
required |
output_function_label
|
str
|
string representing the output function. |
''
|
decimals_to_display
|
int
|
number of decimals to display. |
2
|
output_format
|
Literal['latex', 'console']
|
if set to |
'console'
|
Returns:
Type | Description |
---|---|
List
|
list of strings representing the model |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
|
count_parameters(print_parameters=False)
Counts and returns the parameters (coefficients) of the architecture defined by the highest architecture weights.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
print_parameters
|
bool
|
if set to true, the function will print all parameters. |
False
|
Returns:
Name | Type | Description |
---|---|---|
n_params_total |
int
|
total number of parameters |
n_params_base |
int
|
number of parameters determined by the classifier |
param_list |
list
|
list of parameters specifying the corresponding edge (operation) and value |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|
fix_architecture(switch, new_weights=None)
Freezes or unfreezes the architecture weights.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
switch
|
bool
|
set true to freeze architecture weights or false unfreeze |
required |
new_weights
|
Optional[Tensor]
|
new set of architecture weights |
None
|
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
forward(x)
Computes output of the network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Tensor
|
input to the network |
required |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
genotype(sample=False)
Computes a genotype of the model which specifies the current computation graph based on the largest architecture weight for each edge, or based on a sample. The genotype can be used for parsing or plotting the computation graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample
|
bool
|
if set to true, the architecture will be determined by sampling from a probability distribution that is determined by the softmaxed architecture weights. If set to false (default), the architecture will be determined based on the largest architecture weight per edge. |
False
|
Returns:
Name | Type | Description |
---|---|---|
genotype |
Genotype
|
genotype describing the current (sampled) architecture |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
|
max_alphas_normal()
Samples an architecture from the mixed operations by selecting, for each edge, the operation with the largest architecture weight.
Returns:
Name | Type | Description |
---|---|---|
alphas_normal_sample |
Tensor
|
sampled architecture weights. |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
|
new()
Returns a copy of the network.
Returns:
Type | Description |
---|---|
Module
|
a copy of the network |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
sample_alphas_normal(sample_amp=1, fair_darts_weight_threshold=0)
Samples an architecture from the mixed operations from a probability distribution that is defined by the (softmaxed) architecture weights. This amounts to selecting one operation per edge (i.e., setting the architecture weight of that operation to one while setting the others to zero).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_amp
|
float
|
temperature that is applied before passing the weights through a softmax |
1
|
fair_darts_weight_threshold
|
float
|
used in fair DARTS. If an architecture weight is below this value then it is set to zero. |
0
|
Returns:
Name | Type | Description |
---|---|---|
alphas_normal_sample |
Tensor
|
sampled architecture weights. |
Source code in temp_dir/darts/src/autora/theorist/darts/model_search.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 |
|