API Reference
This page collects the core public modules that are used across the RecDistillery runtime. Topic-specific pages contain the same APIs grouped by workflow.
Core Runtime
RecDistill configuration integration with the new centralized config system.
load_recdistill_config_from_file(config_path: Union[str, Path]) -> RecDistillConfig
Load and validate RecDistill configuration from YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
Union[str, Path]
|
Path to configuration YAML file |
required |
Returns:
| Type | Description |
|---|---|
RecDistillConfig
|
Validated RecDistillConfig object |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If config file doesn't exist |
ValidationError
|
If config doesn't match schema |
Source code in recdistill/config_integration.py
load_recdistill_experiment(dataset_name: str, teacher_model: str, distiller_strategy: str, student_backbone: Optional[str] = None, teacher_framework: str = 'recbole', student_framework: str = 'recbole', overrides: Optional[Dict[str, Any]] = None) -> RecDistillConfig
Programmatically load RecDistill experiment with centralized configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Dataset name (amazon_cd, bookcrossing, citeulike) |
required |
teacher_model
|
str
|
Teacher model (bprmf, nmf, lgcn) |
required |
distiller_strategy
|
str
|
Distillation strategy (de, htd, ftd, unkd) |
required |
student_backbone
|
Optional[str]
|
Student backbone (default: same as teacher) |
None
|
overrides
|
Optional[Dict[str, Any]]
|
Dict of configuration overrides |
None
|
Returns:
| Type | Description |
|---|---|
RecDistillConfig
|
Validated RecDistillConfig object |
Example
config = load_recdistill_experiment( ... dataset_name='citeulike', ... teacher_model='nmf', ... distiller_strategy='de', ... overrides={ ... 'distill_student.optimization.epochs': 50, ... 'distill_student.runtime.seed': 123 ... } ... )
Source code in recdistill/config_integration.py
normalize_recdistill_config(config: Dict[str, Any]) -> Dict[str, Any]
Normalize RecDistill config dictionaries into RecDistillConfig shape.
Source code in recdistill/config_integration.py
recdistill_config_to_dict(config: Union[RecDistillConfig, Dict[str, Any]]) -> Dict[str, Any]
Return a plain normalized dictionary for runner code.
Source code in recdistill/config_integration.py
get_default_dataset_path(dataset_name: str, file_type: str = 'train') -> str
Get default data path for a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_name
|
str
|
Dataset name |
required |
file_type
|
str
|
'train', 'val', or 'test' |
'train'
|
Returns:
| Type | Description |
|---|---|
str
|
Path to dataset file |
Example
path = get_default_dataset_path('citeulike', 'train') print(path) data/citeulike/train.tsv
Source code in recdistill/config_integration.py
print_config_summary(config: RecDistillConfig) -> None
Print a summary of RecDistill configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RecDistillConfig
|
RecDistillConfig object |
required |
Source code in recdistill/config_integration.py
validate_config(config: RecDistillConfig) -> bool
Validate RecDistill configuration for common issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RecDistillConfig
|
RecDistillConfig object |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if configuration is valid, False otherwise |
Source code in recdistill/config_integration.py
list_example_experiments() -> None
Print available pre-configured experiments.
Source code in recdistill/config_integration.py
normalize_backbone_name(backbone: str) -> str
parse_mlp_dims(value: str | list[int] | tuple[int, ...]) -> tuple[int, ...]
build_student_model(*, backbone: str, dataset: InteractionDataset, embedding_dim: int, l2_reg: float = 0.0, lightgcn_layers: int = 2, neumf_mlp_dims: str | list[int] | tuple[int, ...] = '64,32,16,8', neumf_dropout: float = 0.0, framework: str = 'recbole', graph_builder=None)
Source code in recdistill/factories.py
build_distiller_from_args(args: Any, teacher_state: TeacherState, student_dim: int) -> Distiller | None
Source code in recdistill/factories.py
build_student_from_config(student_config: Any, dataset: InteractionDataset, *, optimization_config: Any | None = None, graph_builder=None)
Source code in recdistill/factories.py
build_distiller_from_config(distillation_config: Any, *, teacher_state: TeacherState, student_dim: int) -> Distiller | None
Source code in recdistill/factories.py
FrameworkBatchOutput
dataclass
Source code in recdistill/framework_backbone.py
pos_scores: torch.Tensor
instance-attribute
neg_scores: torch.Tensor
instance-attribute
base_loss: torch.Tensor
instance-attribute
__init__(pos_scores: torch.Tensor, neg_scores: torch.Tensor, base_loss: torch.Tensor) -> None
RecBoleDatasetAdapter
Source code in recdistill/framework_backbone.py
dataset = dataset
instance-attribute
uid_field = 'user_id'
instance-attribute
iid_field = 'item_id'
instance-attribute
inter_num = len(dataset.interactions)
instance-attribute
inter_feat = {self.uid_field: users, self.iid_field: items}
instance-attribute
__init__(dataset: InteractionDataset)
Source code in recdistill/framework_backbone.py
num(field: str) -> int
inter_matrix(form: str = 'coo')
Source code in recdistill/framework_backbone.py
RecBoleBackboneAdapter
Bases: Module
Source code in recdistill/framework_backbone.py
72 73 74 75 76 77 78 79 80 81 82 83 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 180 181 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 | |
backbone = canonical_model_name(backbone)
instance-attribute
dataset = dataset
instance-attribute
embedding_dim = int(embedding_dim)
instance-attribute
l2_reg = float(l2_reg)
instance-attribute
device_name = torch.device(device) if device else torch.device('cuda' if torch.cuda.is_available() else 'cpu')
instance-attribute
config = self._build_config(embedding_dim=(int(embedding_dim)), l2_reg=(float(l2_reg)), lightgcn_layers=(int(lightgcn_layers)), neumf_mlp_dims=(tuple((int(v)) for v in neumf_mlp_dims)), neumf_dropout=(float(neumf_dropout)))
instance-attribute
recbole_dataset = RecBoleDatasetAdapter(dataset)
instance-attribute
model = self._build_model()
instance-attribute
can_score_items_together: bool
property
__init__(*, backbone: str, dataset: InteractionDataset, embedding_dim: int, l2_reg: float = 0.0, lightgcn_layers: int = 2, neumf_mlp_dims: tuple[int, ...] = (64, 32, 16, 8), neumf_dropout: float = 0.0, device: torch.device | str | None = None)
Source code in recdistill/framework_backbone.py
forward(users: torch.Tensor, pos_items: torch.Tensor, neg_items: torch.Tensor) -> FrameworkBatchOutput
Source code in recdistill/framework_backbone.py
compute_base_loss(batch_output: FrameworkBatchOutput) -> torch.Tensor
score_items(users: torch.Tensor, items: torch.Tensor) -> torch.Tensor
Source code in recdistill/framework_backbone.py
score_items_for_user(user: int, num_items: int) -> torch.Tensor
get_all_user_embeddings() -> torch.Tensor
Source code in recdistill/framework_backbone.py
get_all_item_embeddings() -> torch.Tensor
Source code in recdistill/framework_backbone.py
ElliotBackboneAdapter
Bases: Module
Source code in recdistill/framework_backbone.py
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 | |
backbone = canonical_model_name(backbone)
instance-attribute
dataset = dataset
instance-attribute
embedding_dim = int(embedding_dim)
instance-attribute
l2_reg = float(l2_reg)
instance-attribute
device_name = torch.device(device) if device else torch.device('cuda' if torch.cuda.is_available() else 'cpu')
instance-attribute
seed = 42
instance-attribute
edge_index = self._edge_index()
instance-attribute
sparse_graph = None
instance-attribute
ultragcn_constraints = None
instance-attribute
model = self._build_model(lightgcn_layers=(int(lightgcn_layers)), neumf_mlp_dims=neumf_mlp_dims, neumf_dropout=neumf_dropout)
instance-attribute
can_score_items_together: bool
property
__init__(*, backbone: str, dataset: InteractionDataset, embedding_dim: int, l2_reg: float = 0.0, lightgcn_layers: int = 2, neumf_mlp_dims: tuple[int, ...] = (64, 32, 16, 8), neumf_dropout: float = 0.0, device: torch.device | str | None = None)
Source code in recdistill/framework_backbone.py
forward(users: torch.Tensor, pos_items: torch.Tensor, neg_items: torch.Tensor) -> FrameworkBatchOutput
Source code in recdistill/framework_backbone.py
compute_base_loss(batch_output: FrameworkBatchOutput) -> torch.Tensor
score_items(users: torch.Tensor, items: torch.Tensor) -> torch.Tensor
Source code in recdistill/framework_backbone.py
score_items_for_user(user: int, num_items: int) -> torch.Tensor
get_all_user_embeddings() -> torch.Tensor
Source code in recdistill/framework_backbone.py
get_all_item_embeddings() -> torch.Tensor
Source code in recdistill/framework_backbone.py
LensKitBackboneAdapter
Bases: Module
Source code in recdistill/framework_backbone.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 | |
backbone = canonical_model_name(backbone)
instance-attribute
dataset = dataset
instance-attribute
embedding_dim = int(embedding_dim)
instance-attribute
l2_reg = float(l2_reg)
instance-attribute
device_name = torch.device(device) if device else torch.device('cuda' if torch.cuda.is_available() else 'cpu')
instance-attribute
model = self._build_model(lightgcn_layers=(int(lightgcn_layers)), neumf_mlp_dims=neumf_mlp_dims, neumf_dropout=(float(neumf_dropout)))
instance-attribute
can_score_items_together: bool
property
__init__(*, backbone: str, dataset: InteractionDataset, embedding_dim: int, l2_reg: float = 0.0, lightgcn_layers: int = 2, neumf_mlp_dims: tuple[int, ...] = (64, 32, 16, 8), neumf_dropout: float = 0.0, device: torch.device | str | None = None)
Source code in recdistill/framework_backbone.py
forward(users: torch.Tensor, pos_items: torch.Tensor, neg_items: torch.Tensor) -> FrameworkBatchOutput
Source code in recdistill/framework_backbone.py
compute_base_loss(batch_output: FrameworkBatchOutput) -> torch.Tensor
score_items(users: torch.Tensor, items: torch.Tensor) -> torch.Tensor
Source code in recdistill/framework_backbone.py
score_items_for_user(user: int, num_items: int) -> torch.Tensor
get_all_user_embeddings() -> torch.Tensor
Source code in recdistill/framework_backbone.py
get_all_item_embeddings() -> torch.Tensor
Source code in recdistill/framework_backbone.py
build_framework_backbone_adapter(*, framework: str, backbone: str, dataset: InteractionDataset, embedding_dim: int, l2_reg: float = 0.0, lightgcn_layers: int = 2, neumf_mlp_dims: tuple[int, ...] = (64, 32, 16, 8), neumf_dropout: float = 0.0, device: torch.device | str | None = None) -> nn.Module
Source code in recdistill/framework_backbone.py
EMBEDDING_DISTILLERS = frozenset({'DE', 'HTD', 'FTD'})
module-attribute
SCORING_DISTILLERS = frozenset({'RRD', 'UNKD'})
module-attribute
TOPOLOGY_DISTILLERS = frozenset({'HTD', 'FTD'})
module-attribute
DE_FIXED_DIM_UNSAFE_STUDENTS = frozenset({('elliot', 'ngcf'), ('recbole', 'ngcf'), ('recbole', 'spectralcf')})
module-attribute
validate_trainable_model(framework: str, model: str, *, role: str = 'model') -> str
Return the canonical model name if the framework/model pair is trainable by RecDistill.
Source code in recdistill/model_validation.py
validate_distillation_request(*, teacher_framework: str | None, teacher_model: str | None, student_framework: str, student_backbone: str, distiller: str, validate_teacher: bool = True) -> tuple[str | None, str]
Validate a composed distillation run and return canonical teacher/student names.
Source code in recdistill/model_validation.py
validate_recdistill_config_dict(config: dict) -> None
Source code in recdistill/model_validation.py
validate_teacher_representation_request(*, teacher_conf: dict, distiller: str | None) -> None
Source code in recdistill/model_validation.py
validate_loaded_teacher_for_distillation(teacher_state, distiller: str | None) -> None
Source code in recdistill/model_validation.py
REPORTED_TOTAL_MODELS: dict[str, int] = {'recbole': 91, 'elliot': 64, 'lenskit': 23}
module-attribute
REPORTED_TORCH_COMPATIBLE_COUNTS: dict[str, int] = {'recbole': 91, 'elliot': 7, 'lenskit': 5}
module-attribute
REPORTED_TORCH_COMPATIBLE_PERCENTAGES: dict[str, str] = {'recbole': '100%', 'elliot': '10.8%', 'lenskit': '21.7%', 'total': '57.9%'}
module-attribute
REPORTED_TOTAL_IMPORTED_MODELS = 178
module-attribute
REPORTED_TOTAL_TORCH_COMPATIBLE_MODELS = 103
module-attribute
RECBOLE_TORCH_COMPATIBLE_MODELS: tuple[str, ...] = ('AFM', 'AutoInt', 'DCN', 'DCNV2', 'DeepFM', 'DSSM', 'EulerNet', 'FFM', 'FiGNN', 'FM', 'FNN', 'FwFM', 'KD_DAGFM', 'LR', 'NFM', 'PNN', 'WideDeep', 'xDeepFM', 'ADMMSLIM', 'AsymKNN', 'BPR', 'CDAE', 'ConvNCF', 'DGCF', 'DiffRec', 'DMF', 'EASE', 'ENMF', 'FISM', 'GCMC', 'ItemKNN', 'LightGCN', 'LINE', 'MacridVAE', 'MultiDAE', 'MultiVAE', 'NAIS', 'NCEPLRec', 'NCL', 'NeuMF', 'NGCF', 'NNCF', 'Pop', 'RaCT', 'Random', 'RecVAE', 'SGL', 'SimpleX', 'SLIMElastic', 'SpectralCF', 'CFKG', 'CKE', 'KGAT', 'KGCN', 'KGIN', 'KGNNLS', 'KTUP', 'MCCLK', 'MKR', 'RippleNet', 'BERT4Rec', 'Caser', 'CORE', 'DIEN', 'DIN', 'FDSA', 'FEARec', 'FOSSIL', 'FPMC', 'GCSAN', 'GRU4Rec', 'GRU4RecCPR', 'GRU4RecF', 'GRU4RecKG', 'HGN', 'HRM', 'KSR', 'LightSANs', 'NARM', 'NextItNet', 'NPE', 'RepeatNet', 'S3Rec', 'SASRec', 'SASRecCPR', 'SASRecF', 'SHAN', 'SINE', 'SRGNN', 'STAMP', 'TransRec')
module-attribute
ELLIOT_TORCH_COMPATIBLE_MODELS: tuple[str, ...] = ('BPRMF', 'DGCF', 'LightGCN', 'NGCF', 'NeuMFTorch', 'SGL', 'UltraGCN')
module-attribute
LENSKIT_TORCH_COMPATIBLE_MODELS: tuple[str, ...] = ('BPR', 'EASEScorer', 'FlexMFExplicitScorer', 'FlexMFImplicitScorer', 'LightGCNScorer')
module-attribute
TORCH_COMPATIBLE_IMPORTED_MODELS: tuple[TorchCompatibleModel, ...] = tuple((TorchCompatibleModel('recbole', name)) for name in RECBOLE_TORCH_COMPATIBLE_MODELS) + tuple((TorchCompatibleModel('elliot', name, 'Torch implementation of Elliot NeuMF.')) for name in ELLIOT_TORCH_COMPATIBLE_MODELS) + tuple((TorchCompatibleModel('lenskit', name)) for name in LENSKIT_TORCH_COMPATIBLE_MODELS)
module-attribute
TRAINABLE_BACKBONES: tuple[TrainableBackbone, ...] = (TrainableBackbone(framework='recbole', model='BPRMF', aliases=('BPR', 'BPRMF'), adapter='RecBoleBackboneAdapter', implementation='recommenders.recbole.model.general_recommender.bpr.BPR'), TrainableBackbone(framework='recbole', model='LINE', aliases=('LINE',), adapter='RecBoleBackboneAdapter', implementation='recommenders.recbole.model.general_recommender.line.LINE'), TrainableBackbone(framework='recbole', model='LGCN', aliases=('LGCN', 'LightGCN'), adapter='RecBoleBackboneAdapter', implementation='recommenders.recbole.model.general_recommender.lightgcn.LightGCN'), TrainableBackbone(framework='recbole', model='NGCF', aliases=('NGCF',), adapter='RecBoleBackboneAdapter', implementation='recommenders.recbole.model.general_recommender.ngcf.NGCF'), TrainableBackbone(framework='recbole', model='DGCF', aliases=('DGCF',), adapter='RecBoleBackboneAdapter', implementation='recommenders.recbole.model.general_recommender.dgcf.DGCF'), TrainableBackbone(framework='recbole', model='SGL', aliases=('SGL',), adapter='RecBoleBackboneAdapter', implementation='recommenders.recbole.model.general_recommender.sgl.SGL'), TrainableBackbone(framework='recbole', model='SPECTRALCF', aliases=('SpectralCF', 'SPECTRALCF'), adapter='RecBoleBackboneAdapter', implementation='recommenders.recbole.model.general_recommender.spectralcf.SpectralCF'), TrainableBackbone(framework='recbole', model='NMF', aliases=('NMF', 'NeuMF'), adapter='RecBoleBackboneAdapter', implementation='recommenders.recbole.model.general_recommender.neumf.NeuMF'), TrainableBackbone(framework='elliot', model='BPRMF', aliases=('BPR', 'BPRMF'), adapter='ElliotBackboneAdapter', implementation='recommenders.elliot.torch.bprmf.BPRMFModel'), TrainableBackbone(framework='elliot', model='NMF', aliases=('NMF', 'NeuMF'), adapter='ElliotBackboneAdapter', implementation='recommenders.elliot.neural.NeuMF.neural_matrix_factorization_torch_model.NeuralMatrixFactorizationTorchModel'), TrainableBackbone(framework='elliot', model='LGCN', aliases=('LGCN', 'LightGCN'), adapter='ElliotBackboneAdapter', implementation='recommenders.elliot.torch.lightgcn.LightGCNModel'), TrainableBackbone(framework='elliot', model='NGCF', aliases=('NGCF',), adapter='ElliotBackboneAdapter', implementation='recommenders.elliot.torch.ngcf.NGCFModel'), TrainableBackbone(framework='elliot', model='DGCF', aliases=('DGCF',), adapter='ElliotBackboneAdapter', implementation='recommenders.elliot.torch.dgcf.DGCFModel'), TrainableBackbone(framework='elliot', model='SGL', aliases=('SGL',), adapter='ElliotBackboneAdapter', implementation='recommenders.elliot.torch.sgl.SGLModel'), TrainableBackbone(framework='elliot', model='ULTRAGCN', aliases=('UltraGCN', 'ULTRAGCN'), adapter='ElliotBackboneAdapter', implementation='recommenders.elliot.torch.ultragcn.UltraGCNModel'), TrainableBackbone(framework='lenskit', model='BPRMF', aliases=('BPRMF',), adapter='LensKitBackboneAdapter', implementation='recommenders.lenskit.flexmf._model.FlexMFModel', notes='LensKit FlexMF configured as matrix factorization without biases.'), TrainableBackbone(framework='lenskit', model='LGCN', aliases=('LGCN', 'LightGCN'), adapter='LensKitBackboneAdapter', implementation='recommenders.lenskit.graphs.lightgcn.LightGCN'))
module-attribute
UNSUPPORTED_KNOWN_BACKBONES: tuple[UnsupportedBackbone, ...] = (UnsupportedBackbone(framework='lenskit', model='NMF', reason='The imported LensKit models do not include a native NeuMF/NMF implementation.', recommended_path='Use RecBole/Elliot NeuMF, or import an external teacher with import_teacher.py.'),)
module-attribute
TrainableBackbone
dataclass
Source code in recdistill/supported_models.py
framework: str
instance-attribute
model: str
instance-attribute
aliases: tuple[str, ...]
instance-attribute
adapter: str
instance-attribute
implementation: str
instance-attribute
notes: str = ''
class-attribute
instance-attribute
__init__(framework: str, model: str, aliases: tuple[str, ...], adapter: str, implementation: str, notes: str = '') -> None
UnsupportedBackbone
dataclass
Source code in recdistill/supported_models.py
framework: str
instance-attribute
model: str
instance-attribute
reason: str
instance-attribute
recommended_path: str
instance-attribute
__init__(framework: str, model: str, reason: str, recommended_path: str) -> None
TorchCompatibleModel
dataclass
Source code in recdistill/supported_models.py
framework: str
instance-attribute
name: str
instance-attribute
note: str = ''
class-attribute
instance-attribute
__init__(framework: str, name: str, note: str = '') -> None
torch_compatible_by_framework() -> dict[str, list[TorchCompatibleModel]]
Source code in recdistill/supported_models.py
torch_compatible_summary_rows() -> list[dict[str, str]]
Source code in recdistill/supported_models.py
trainable_by_framework() -> dict[str, list[TrainableBackbone]]
unsupported_by_framework() -> dict[str, list[UnsupportedBackbone]]
Source code in recdistill/supported_models.py
MODEL_ALIASES = {'bprmf': 'BPRMF', 'bpr': 'BPRMF', 'line': 'LINE', 'lgcn': 'LGCN', 'lightgcn': 'LGCN', 'ngcf': 'NGCF', 'dgcf': 'DGCF', 'sgl': 'SGL', 'ultragcn': 'ULTRAGCN', 'ultra_gcn': 'ULTRAGCN', 'spectralcf': 'SPECTRALCF', 'spectral_cf': 'SPECTRALCF', 'nmf': 'NMF', 'nfm': 'NMF', 'neumf': 'NMF', 'neumftorch': 'NMF'}
module-attribute
DISTILLER_ALIASES = {'de': 'DE', 'distillation_experts': 'DE', 'rrd': 'RRD', 'relaxed_ranking_distillation': 'RRD', 'unkd': 'UNKD', 'unkd_distillation': 'UNKD', 'htd': 'HTD', 'hierarchical_topology_distillation': 'HTD', 'ftd': 'FTD', 'full_topology_distillation': 'FTD'}
module-attribute
SUPPORTED_BACKBONES = frozenset({'BPRMF', 'LINE', 'LGCN', 'NGCF', 'DGCF', 'SGL', 'ULTRAGCN', 'SPECTRALCF', 'NMF'})
module-attribute
SUPPORTED_DISTILLERS = frozenset({'DE', 'RRD', 'UNKD', 'HTD', 'FTD'})
module-attribute
canonical_model_name(value: str) -> str
Source code in recdistill/registry.py
canonical_distiller_name(value: str) -> str
Source code in recdistill/registry.py
parse_distiller_methods(value: str | None) -> tuple[str, ...]
Source code in recdistill/registry.py
distiller_slug(value: str | None) -> str
Experiment Runtime
RecDistillExperimentRunner
Source code in recdistill/experiment_runner.py
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 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 180 181 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 | |
config = args if isinstance(args, RecDistillConfig) else None
instance-attribute
args = runner_args_from_config(args) if isinstance(args, RecDistillConfig) else args
instance-attribute
wandb_logger = wandb_logger
instance-attribute
device = torch.device(args.device) if args.device else torch.device('cuda' if torch.cuda.is_available() else 'cpu')
instance-attribute
student_backbone = normalize_backbone_name(args.student_backbone)
instance-attribute
teacher_source = _teacher_source_from_args(args)
instance-attribute
teacher_path = self.teacher_source.path
instance-attribute
output_path = _distilled_student_path(resolve_student_checkpoint_from_args(args, distiller_name=(self.resolve_distiller_name())))
instance-attribute
run_dir = self.output_path.parent.parent if self.output_path.parent.name == 'artifacts' else self.output_path.parent
instance-attribute
teacher_state = None
instance-attribute
dataset = None
instance-attribute
val_dict: dict[int, set[int]] = {}
instance-attribute
test_dict: dict[int, set[int]] = {}
instance-attribute
model = None
instance-attribute
distiller = None
instance-attribute
optimizer = None
instance-attribute
trainer = None
instance-attribute
__init__(args: Any, wandb_logger=None)
Source code in recdistill/experiment_runner.py
from_config(config: RecDistillConfig, wandb_logger=None) -> 'RecDistillExperimentRunner'
classmethod
resolve_distiller_name() -> str
Source code in recdistill/experiment_runner.py
run_config() -> dict[str, Any]
Source code in recdistill/experiment_runner.py
prepare() -> None
Source code in recdistill/experiment_runner.py
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 180 181 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 | |
run() -> dict[str, Any]
train() -> dict[str, Any]
Source code in recdistill/experiment_runner.py
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 | |
runner_args_from_config(config: RecDistillConfig) -> SimpleNamespace
Source code in recdistill/experiment_runner.py
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 | |
NativeTrainingArgs
dataclass
Source code in recdistill/native_runner.py
role: str
instance-attribute
dataset: str
instance-attribute
backbone: str
instance-attribute
embedding_dim: int
instance-attribute
framework: str = 'recbole'
class-attribute
instance-attribute
epochs: int = 100
class-attribute
instance-attribute
batch_size: int = 512
class-attribute
instance-attribute
learning_rate: float = 0.001
class-attribute
instance-attribute
l2_reg: float = 0.0001
class-attribute
instance-attribute
dropout: float = 0.0
class-attribute
instance-attribute
lightgcn_layers: int = 2
class-attribute
instance-attribute
neumf_mlp_dims: str = '64,32,16,8'
class-attribute
instance-attribute
seed: int = 42
class-attribute
instance-attribute
device: str | None = None
class-attribute
instance-attribute
num_workers: int = 0
class-attribute
instance-attribute
output_path: str | None = None
class-attribute
instance-attribute
save_every: int = 0
class-attribute
instance-attribute
skip_eval: bool = False
class-attribute
instance-attribute
eval_k: int = 20
class-attribute
instance-attribute
eval_every: int = 5
class-attribute
instance-attribute
eval_batch_size: int = 1024
class-attribute
instance-attribute
eval_val_only: bool = True
class-attribute
instance-attribute
selection_split: str = 'val'
class-attribute
instance-attribute
selection_metric: str = 'ndcg'
class-attribute
instance-attribute
assert_no_train_leak: bool = True
class-attribute
instance-attribute
early_stop: bool = False
class-attribute
instance-attribute
early_stop_mode: str = 'val_metric'
class-attribute
instance-attribute
early_stop_metric: str = 'ndcg'
class-attribute
instance-attribute
early_stop_patience: int = 10
class-attribute
instance-attribute
early_stop_min_delta: float = 0.0
class-attribute
instance-attribute
early_stop_warmup: int = 0
class-attribute
instance-attribute
early_stop_restore_best: bool = False
class-attribute
instance-attribute
config_path: str | None = None
class-attribute
instance-attribute
__init__(role: str, dataset: str, backbone: str, embedding_dim: int, framework: str = 'recbole', epochs: int = 100, batch_size: int = 512, learning_rate: float = 0.001, l2_reg: float = 0.0001, dropout: float = 0.0, lightgcn_layers: int = 2, neumf_mlp_dims: str = '64,32,16,8', seed: int = 42, device: str | None = None, num_workers: int = 0, output_path: str | None = None, save_every: int = 0, skip_eval: bool = False, eval_k: int = 20, eval_every: int = 5, eval_batch_size: int = 1024, eval_val_only: bool = True, selection_split: str = 'val', selection_metric: str = 'ndcg', assert_no_train_leak: bool = True, early_stop: bool = False, early_stop_mode: str = 'val_metric', early_stop_metric: str = 'ndcg', early_stop_patience: int = 10, early_stop_min_delta: float = 0.0, early_stop_warmup: int = 0, early_stop_restore_best: bool = False, config_path: str | None = None) -> None
NativeModelTrainingRunner
Source code in recdistill/native_runner.py
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 | |
args = args
instance-attribute
role = _normalize_role(args.role)
instance-attribute
device = torch.device(args.device) if args.device else torch.device('cuda' if torch.cuda.is_available() else 'cpu')
instance-attribute
backbone = normalize_backbone_name(args.backbone)
instance-attribute
output_path = Path(args.output_path) if args.output_path else self._default_output_path()
instance-attribute
run_dir = self.output_path.parent.parent if self.output_path.parent.name == 'artifacts' else self.output_path.parent
instance-attribute
dataset = None
instance-attribute
val_dict: dict[int, set[int]] = {}
instance-attribute
test_dict: dict[int, set[int]] = {}
instance-attribute
model = None
instance-attribute
optimizer = None
instance-attribute
trainer = None
instance-attribute
__init__(args: NativeTrainingArgs)
Source code in recdistill/native_runner.py
run_config() -> dict[str, Any]
Source code in recdistill/native_runner.py
prepare() -> None
Source code in recdistill/native_runner.py
run() -> dict[str, Any]
train() -> dict[str, Any]
Source code in recdistill/native_runner.py
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 | |
native_args_from_model_config(*, role: str, dataset: str, backbone: str, overrides: dict[str, Any] | None = None) -> NativeTrainingArgs
Source code in recdistill/native_runner.py
native_args_to_config(args: NativeTrainingArgs) -> dict[str, Any]
Source code in recdistill/native_runner.py
native_args_from_config_file(path: str | Path, *, role: str, fallback_dataset: str | None = None, fallback_backbone: str | None = None, overrides: dict[str, Any] | None = None) -> NativeTrainingArgs
Source code in recdistill/native_runner.py
native_args_from_config(config: dict[str, Any], *, role: str, config_path: str | Path | None = None, fallback_dataset: str | None = None, fallback_backbone: str | None = None, overrides: dict[str, Any] | None = None) -> NativeTrainingArgs
Source code in recdistill/native_runner.py
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 | |
PositiveInteractionDataset
Bases: Dataset
Source code in recdistill/training.py
__init__(interactions: list[tuple[int, int]])
__len__() -> int
BPRBatchCollator
Source code in recdistill/training.py
negative_sampler = negative_sampler
instance-attribute
__init__(negative_sampler: BPRNegativeSampler)
__call__(batch_rows: list[tuple[int, int]])
Source code in recdistill/training.py
set_seed(seed: int) -> None
build_train_loader(dataset: InteractionDataset, batch_size: int, num_workers: int = 0) -> torch.utils.data.DataLoader
Source code in recdistill/training.py
build_lightgcn_graph(dataset: InteractionDataset) -> torch.Tensor
Source code in recdistill/training.py
prepare_distiller_trainable_modules(distiller, student_dim: int, device: torch.device) -> None
Source code in recdistill/training.py
evaluate_embeddings(user_embeddings: torch.Tensor, item_embeddings: torch.Tensor, train_seen: dict[int, set[int]], ground_truth: dict[int, set[int]], top_k: int, batch_size: int, device: torch.device, scorer: TeacherScorer | None = None) -> tuple[dict[str, float], int]
Evaluate top-k recommendations from embeddings or a scorer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_embeddings
|
Tensor
|
User embedding matrix, or |
required |
item_embeddings
|
Tensor
|
Item embedding matrix, or |
required |
train_seen
|
dict[int, set[int]]
|
Training items keyed by user. These items are masked before ranking. |
required |
ground_truth
|
dict[int, set[int]]
|
Held-out target items keyed by user. |
required |
top_k
|
int
|
Recommendation cutoff. |
required |
batch_size
|
int
|
Number of users per embedding-ranking batch. |
required |
device
|
device
|
Torch device used for score computation. |
required |
scorer
|
TeacherScorer | None
|
Optional object implementing |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
A pair containing the metric dictionary and the number of users whose |
int
|
raw top-k list still contained a training item before final filtering. |
Source code in recdistill/evaluation.py
evaluate_teacher(teacher_state: TeacherState, train_seen: dict[int, set[int]], val_gt: dict[int, set[int]], test_gt: dict[int, set[int]], top_k: int, batch_size: int, device: torch.device, eval_val_only: bool = False) -> dict[str, dict[str, float] | int]
Evaluate a serialized or imported teacher on validation/test splits.
The teacher may expose either user/item embeddings or a scorer-only representation such as a precomputed score matrix or top-k predictions. Training interactions are masked before ranking so the metrics are computed only over unseen candidate items.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
teacher_state
|
TeacherState
|
Runtime teacher representation loaded from a |
required |
train_seen
|
dict[int, set[int]]
|
Mapping from user index to training items that must be removed from the ranked candidate set. |
required |
val_gt
|
dict[int, set[int]]
|
Validation ground-truth items keyed by user index. |
required |
test_gt
|
dict[int, set[int]]
|
Test ground-truth items keyed by user index. |
required |
top_k
|
int
|
Recommendation cutoff used by precision, recall, NDCG and hit ratio. |
required |
batch_size
|
int
|
Number of users evaluated per embedding-ranking batch. |
required |
device
|
device
|
Torch device used for score computation. |
required |
eval_val_only
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, float] | int]
|
A dictionary with split metrics and train-leakage counters. The metric |
dict[str, dict[str, float] | int]
|
dictionaries contain |
Source code in recdistill/evaluation.py
evaluate_student(model: torch.nn.Module, train_seen: dict[int, set[int]], val_gt: dict[int, set[int]], test_gt: dict[int, set[int]], top_k: int, batch_size: int, device: torch.device, eval_val_only: bool = False) -> dict[str, dict[str, float] | int]
Evaluate a trained student model on validation and test splits.
The student must expose get_all_user_embeddings and
get_all_item_embeddings. If it also implements score_items_for_user,
that scorer is used for ranking.