warprec 2.1.7__tar.gz → 2.1.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {warprec-2.1.7 → warprec-2.1.9}/PKG-INFO +1 -1
- {warprec-2.1.7 → warprec-2.1.9}/pyproject.toml +1 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/dataset.py +5 -0
- warprec-2.1.9/warprec/data/entities/common.py +355 -0
- warprec-2.1.9/warprec/data/stash.py +69 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/evaluator.py +43 -2
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/auc.py +1 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/f1.py +1 -2
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/gauc.py +2 -2
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/ndcg.py +3 -6
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/base_metric.py +80 -15
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/coverage/item_coverage.py +1 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/coverage/user_coverage.py +1 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/coverage/user_coverage_at_n.py +6 -2
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/debiased/base.py +4 -11
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/diversity/gini_index.py +1 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/diversity/shannon_entropy.py +1 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/fairness/biasdisparitybd.py +1 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/fairness/biasdisparitybs.py +5 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/fairness/itemmadranking.py +2 -2
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/fairness/itemmadrating.py +6 -3
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/fairness/usermadranking.py +5 -8
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/fairness/usermadrating.py +2 -2
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/multiobjective/euclideandistance.py +1 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/multiobjective/hypervolume.py +1 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/pipelines/design.py +2 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/pipelines/estimate.py +101 -14
- {warprec-2.1.7 → warprec-2.1.9}/warprec/pipelines/eval.py +2 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/pipelines/remotes/ml.py +6 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/pipelines/swarm.py +168 -3
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/base_recommender.py +51 -11
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/callbacks.py +190 -1
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/cdae.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/diffrec.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/elsa.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/macridvae.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/multidae.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/multivae.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/dgcf.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/egcf.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/esigcf.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/gcmc.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightccf.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcl.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcn.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcnpp.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgode.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/macrgcn.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/mixrec.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/ngcf.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/paac.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/popdcl.py +0 -7
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/recdcl.py +0 -6
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/sgcl.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/sgl.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/simgcl.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/simrec.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/ultragcn.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/xsimgcl.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/bpr.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/fism.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/macrmf.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/neural/convncf.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/neural/neumf.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/neural/twotower.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/context_aware_recommender/afm.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/context_aware_recommender/dcn.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/context_aware_recommender/dcnv2.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/context_aware_recommender/deepfm.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/context_aware_recommender/fm.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/context_aware_recommender/nfm.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/context_aware_recommender/wideanddeep.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/context_aware_recommender/xdeepfm.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/knowledge_aware_recommender/cke.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/knowledge_aware_recommender/kahfm.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/knowledge_aware_recommender/kgat.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/knowledge_aware_recommender/kgcn.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/knowledge_aware_recommender/kgflex.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/knowledge_aware_recommender/kgin.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/knowledge_aware_recommender/ripplenet.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/multimodal_recommender/bm3.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/multimodal_recommender/freedom.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/multimodal_recommender/lattice.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/multimodal_recommender/mgcn.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/multimodal_recommender/mmgcn.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/multimodal_recommender/vbpr.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/bert4rec.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/bsarec.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/caser.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/cl4srec.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/core.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/duorec.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/esasrec.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/fossil.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/gru4rec.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/gsasrec.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/lightsans.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/linrec.py +0 -4
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/narm.py +0 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/sasrec.py +0 -5
- warprec-2.1.9/warprec/recommenders/trainer/dashboard_callbacks.py +209 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/trainer/objectives.py +27 -3
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/trainer/trainer.py +39 -11
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/__init__.py +0 -2
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/model_configuration.py +26 -5
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/enums.py +0 -102
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/helpers.py +52 -2
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/registry.py +48 -0
- warprec-2.1.7/warprec/data/entities/common.py +0 -131
- warprec-2.1.7/warprec/recommenders/trainer/dashboard_callbacks.py +0 -103
- {warprec-2.1.7 → warprec-2.1.9}/LICENSE +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/README.md +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/common/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/common/initialize.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/common/run_state.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/common/std_logs.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/context.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/interactions.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/knowledge.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/multimodal.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/sessions.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/train_structures/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/train_structures/custom_collate_fn.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/train_structures/interaction_structures.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/train_structures/session_structures.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/entities/transactions.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/eval_loaders.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/filtering.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/ranking.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/reader/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/reader/azureblob_reader.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/reader/base_reader.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/reader/local_reader.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/schema.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/splitting/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/splitting/splitter.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/splitting/strategies.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/writer/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/writer/azureblob_writer.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/writer/base_writer.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/data/writer/local_writer.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/factory.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/hit_rate.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/lauc.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/logloss.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/map.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/mar.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/mrr.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/precision.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/accuracy/recall.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/bias/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/bias/aclt.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/bias/aplt.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/bias/arp.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/bias/long_tail.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/bias/pop_reo.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/bias/pop_rsp.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/coverage/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/coverage/numretrieved.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/debiased/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/debiased/dcg.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/debiased/recall.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/diversity/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/diversity/srecall.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/fairness/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/fairness/biasdisparitybr.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/fairness/reo.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/fairness/rsp.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/multiobjective/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/novelty/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/novelty/efd.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/novelty/epc.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/novelty/novelty_profile.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/rating/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/rating/mae.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/rating/mse.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/metrics/rating/rmse.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/propensity.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/evaluation/statistical_significance.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/pipelines/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/pipelines/common.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/pipelines/remotes/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/pipelines/remotes/data.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/pipelines/train.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/ease.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/sansa.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/graph_utils.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/graph_based/rp3beta.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/knn/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/knn/itemknn.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/knn/itemknntd.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/knn/userknn.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/knn/userknntd.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/admmslim.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/ials.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/ials2008.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/slim.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/collaborative_filtering_recommender/neural/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/content_based_recommender/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/content_based_recommender/vsm.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/context_aware_recommender/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/hybrid_recommender/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/hybrid_recommender/addease.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/hybrid_recommender/attributeitemknn.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/hybrid_recommender/attributeuserknn.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/hybrid_recommender/cease.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/knowledge_aware_recommender/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/knowledge_aware_recommender/knowledge_utils.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/layers.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/losses.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/lr_scheduler_wrapper.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/multimodal_recommender/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/multimodal_recommender/multimodal_utils.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/optimizer_wrapper.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/proxy.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/reranking/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/reranking/base.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/reranking/calibration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/reranking/factory.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/reranking/mmr.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/sequential_recommender/stan.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/similarities.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/trainer/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/trainer/logger_callbacks.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/trainer/runtime.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/trainer/scheduler_wrapper.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/trainer/search_algorithm_wrapper.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/unpersonalized_recommender/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/unpersonalized_recommender/pop.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/recommenders/unpersonalized_recommender/random.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/run.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serve.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/api.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/app.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/catalogue.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/context.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/deployments.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/errors.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/mcp.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/payload.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/schemas.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/serving/servable.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/callback.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/common.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/dashboard_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/estimate_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/evaluation_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/general_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/reader_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/autoencoder_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/graph_based_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/knn_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/latent_factor_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/neural_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/content_based_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/context_aware_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/hybrid_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/knowledge_aware_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/multimodal_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/sequential_model_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/recommender_model_config/unpersonalized_config.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/rerank_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/run_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/search_space_wrapper.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/serving_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/splitter_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/training_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/config/writer_configuration.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/logger/__init__.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/logger/logger.py +0 -0
- {warprec-2.1.7 → warprec-2.1.9}/warprec/utils/pause.py +0 -0
|
@@ -20,6 +20,7 @@ from warprec.data.entities import (
|
|
|
20
20
|
Sessions,
|
|
21
21
|
Transactions,
|
|
22
22
|
)
|
|
23
|
+
from warprec.data.stash import METRIC_ARGUMENTS, MODEL_ARGUMENTS, check_stash
|
|
23
24
|
from warprec.data.schema import ColumnLabels, ContextSpec, SideData, SignalOptions
|
|
24
25
|
from warprec.data.eval_loaders import (
|
|
25
26
|
EvaluationDataset,
|
|
@@ -1366,10 +1367,14 @@ class Dataset:
|
|
|
1366
1367
|
def add_to_stash(self, key: str, value: Any):
|
|
1367
1368
|
"""Add a custom structure to the stash.
|
|
1368
1369
|
|
|
1370
|
+
The stash is passed to every model and every metric next to the
|
|
1371
|
+
arguments WarpRec gives them, so those names cannot be used.
|
|
1372
|
+
|
|
1369
1373
|
Args:
|
|
1370
1374
|
key (str): The key of the custom structure.
|
|
1371
1375
|
value (Any): The value of the custom structure.
|
|
1372
1376
|
"""
|
|
1377
|
+
check_stash({key: value}, MODEL_ARGUMENTS | METRIC_ARGUMENTS, "model or metric")
|
|
1373
1378
|
self._stash[key] = value
|
|
1374
1379
|
|
|
1375
1380
|
def update_mappings(self, user_mapping: dict, item_mapping: dict):
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import pickle # nosec B403 - only WarpRec's own worker and checkpoint state
|
|
2
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
3
|
+
|
|
4
|
+
import narwhals as nw
|
|
5
|
+
import numpy as np
|
|
6
|
+
import torch
|
|
7
|
+
from narwhals.dataframe import DataFrame
|
|
8
|
+
from torch.utils.data import DataLoader, Dataset, default_collate
|
|
9
|
+
|
|
10
|
+
USER_INDEX = "__uidx__"
|
|
11
|
+
ITEM_INDEX = "__iidx__"
|
|
12
|
+
ROW_INDEX = "__row__"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _rng_holders(dataset: Any) -> List[Any]:
|
|
16
|
+
"""The objects a training dataset draws its random samples from.
|
|
17
|
+
|
|
18
|
+
A dataset samples either through an 'rng' of its own or through the 'rng'
|
|
19
|
+
of its negative sampler. Seeding a worker and saving a loader's state for a
|
|
20
|
+
resume both have to reach the same generators, so they find them here.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
dataset (Any): The dataset of a DataLoader.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
List[Any]: The dataset and its sampler, those of them holding an 'rng'.
|
|
27
|
+
"""
|
|
28
|
+
return [
|
|
29
|
+
holder
|
|
30
|
+
for holder in (dataset, getattr(dataset, "sampler", None))
|
|
31
|
+
if hasattr(holder, "rng")
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_generator_state(generator: Any) -> Any:
|
|
36
|
+
"""Read the state of a random generator, whatever library it comes from.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
generator (Any): A numpy Generator or RandomState, a torch Generator or
|
|
40
|
+
a Python random.Random.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
Any: A picklable copy of its state.
|
|
44
|
+
"""
|
|
45
|
+
if isinstance(generator, np.random.Generator):
|
|
46
|
+
return generator.bit_generator.state
|
|
47
|
+
if isinstance(generator, (torch.Generator, np.random.RandomState)):
|
|
48
|
+
return generator.get_state()
|
|
49
|
+
return generator.getstate()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def set_generator_state(generator: Any, state: Any) -> None:
|
|
53
|
+
"""Put a random generator back in a state read by 'get_generator_state'.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
generator (Any): The generator to restore, of the same kind as the one
|
|
57
|
+
the state was read from.
|
|
58
|
+
state (Any): The state.
|
|
59
|
+
"""
|
|
60
|
+
if isinstance(generator, np.random.Generator):
|
|
61
|
+
generator.bit_generator.state = state
|
|
62
|
+
elif isinstance(generator, (torch.Generator, np.random.RandomState)):
|
|
63
|
+
generator.set_state(state)
|
|
64
|
+
else:
|
|
65
|
+
generator.setstate(state)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def seed_worker(worker_id: int) -> None:
|
|
69
|
+
"""Seed a DataLoader worker so that sampling is reproducible.
|
|
70
|
+
|
|
71
|
+
Each worker receives its own copy of the dataset, so without this they would
|
|
72
|
+
all inherit the same generator state and draw the same negatives. Torch
|
|
73
|
+
already gives every worker a distinct, seed-derived initial seed, so that is
|
|
74
|
+
what the copies are reseeded from: the run stays reproducible while the
|
|
75
|
+
workers stay independent of one another.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
worker_id (int): The index of the worker being seeded.
|
|
79
|
+
"""
|
|
80
|
+
worker_seed = torch.initial_seed() % 2**32
|
|
81
|
+
np.random.seed(worker_seed)
|
|
82
|
+
|
|
83
|
+
info = torch.utils.data.get_worker_info()
|
|
84
|
+
for holder in _rng_holders(getattr(info, "dataset", None)):
|
|
85
|
+
holder.rng = np.random.default_rng(worker_seed)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class WorkerRandomState:
|
|
89
|
+
"""Collate function that keeps track of what persistent workers have drawn.
|
|
90
|
+
|
|
91
|
+
A persistent worker keeps its copy of the dataset, and so its sampling
|
|
92
|
+
generators, from one epoch to the next. That state lives in the worker
|
|
93
|
+
process, out of reach of the checkpoint a resumed trial restarts from, so
|
|
94
|
+
a resumed trial used to draw different negatives than the uninterrupted
|
|
95
|
+
run from the first epoch it repeated onwards.
|
|
96
|
+
|
|
97
|
+
The wrapper runs in the worker after every batch it builds. It writes the
|
|
98
|
+
state of the worker's generators to a slot of shared memory, which the
|
|
99
|
+
checkpoint reads at the end of an epoch, when every batch of the epoch has
|
|
100
|
+
been delivered and the workers are idle.
|
|
101
|
+
|
|
102
|
+
Restoring works the other way round. The state is handed to the workers
|
|
103
|
+
when they start, but it must take effect only once they reach the first
|
|
104
|
+
batch of the resumed epoch: the loader iterator Lightning creates before
|
|
105
|
+
the first epoch has already given every worker its first 'prefetch_factor'
|
|
106
|
+
batches, which a resumed trial discards. Each worker therefore counts the
|
|
107
|
+
batches it builds and adopts the saved state after the last discarded one.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
collate_fn (Optional[Callable[[Any], Any]]): The collate function to
|
|
111
|
+
wrap. None stands for PyTorch's default collation.
|
|
112
|
+
num_workers (int): The number of workers of the loader.
|
|
113
|
+
|
|
114
|
+
Attributes:
|
|
115
|
+
SLOT_BYTES (int): The shared memory given to the state of one worker.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
SLOT_BYTES: int = 16384
|
|
119
|
+
|
|
120
|
+
def __init__(self, collate_fn: Optional[Callable[[Any], Any]], num_workers: int):
|
|
121
|
+
self.collate_fn = collate_fn or default_collate
|
|
122
|
+
self.slots = torch.zeros((num_workers, self.SLOT_BYTES), dtype=torch.uint8)
|
|
123
|
+
self.slots.share_memory_()
|
|
124
|
+
self.pending: Optional[List[Optional[bytes]]] = None
|
|
125
|
+
self.skip: List[int] = []
|
|
126
|
+
self._built = 0
|
|
127
|
+
|
|
128
|
+
def __call__(self, batch: Any) -> Any:
|
|
129
|
+
"""Collate a batch, then record the state of this worker's generators.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
batch (Any): The samples of the batch.
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
Any: The collated batch.
|
|
136
|
+
"""
|
|
137
|
+
collated = self.collate_fn(batch)
|
|
138
|
+
info = torch.utils.data.get_worker_info()
|
|
139
|
+
if info is None:
|
|
140
|
+
return collated
|
|
141
|
+
|
|
142
|
+
holders = _rng_holders(info.dataset)
|
|
143
|
+
self._built += 1
|
|
144
|
+
if self.pending is not None and self._built == self.skip[info.id]:
|
|
145
|
+
saved = self.pending[info.id]
|
|
146
|
+
if saved is not None:
|
|
147
|
+
states = pickle.loads(saved) # nosec B301 - written by this loader
|
|
148
|
+
for holder, state in zip(holders, states):
|
|
149
|
+
set_generator_state(holder.rng, state)
|
|
150
|
+
self.pending = None
|
|
151
|
+
|
|
152
|
+
record = pickle.dumps([get_generator_state(h.rng) for h in holders])
|
|
153
|
+
slot = self.slots[info.id]
|
|
154
|
+
if len(record) + 4 > self.SLOT_BYTES:
|
|
155
|
+
slot[:4] = torch.tensor([255, 255, 255, 255], dtype=torch.uint8)
|
|
156
|
+
else:
|
|
157
|
+
header = len(record).to_bytes(4, "little")
|
|
158
|
+
slot[: 4 + len(record)] = torch.frombuffer(
|
|
159
|
+
bytearray(header + record), dtype=torch.uint8
|
|
160
|
+
)
|
|
161
|
+
return collated
|
|
162
|
+
|
|
163
|
+
def snapshot(self) -> Optional[List[Optional[bytes]]]:
|
|
164
|
+
"""The last state each worker recorded.
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
Optional[List[Optional[bytes]]]: One entry per worker, None for a
|
|
168
|
+
worker that has built no batch yet. None when a state did not
|
|
169
|
+
fit its slot and cannot be saved.
|
|
170
|
+
"""
|
|
171
|
+
states: List[Optional[bytes]] = []
|
|
172
|
+
for slot in self.slots:
|
|
173
|
+
raw = bytes(slot.numpy())
|
|
174
|
+
size = int.from_bytes(raw[:4], "little")
|
|
175
|
+
if size == 0xFFFFFFFF:
|
|
176
|
+
return None
|
|
177
|
+
states.append(raw[4 : 4 + size] if size else None)
|
|
178
|
+
return states
|
|
179
|
+
|
|
180
|
+
def prime(self, states: List[Optional[bytes]], loader: DataLoader) -> None:
|
|
181
|
+
"""Hand saved states to the workers the loader is about to start.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
states (List[Optional[bytes]]): The states 'snapshot' returned.
|
|
185
|
+
loader (DataLoader): The loader, whose length and prefetch factor
|
|
186
|
+
tell how many batches each worker builds before the epoch the
|
|
187
|
+
trial resumes from.
|
|
188
|
+
"""
|
|
189
|
+
workers = loader.num_workers
|
|
190
|
+
first_requests = min(workers * (loader.prefetch_factor or 2), len(loader))
|
|
191
|
+
self.skip = [len(range(w, first_requests, workers)) for w in range(workers)]
|
|
192
|
+
self.pending = list(states)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def loader_random_state(loader: DataLoader) -> Dict[str, Any]:
|
|
196
|
+
"""Everything that decides the batches a training loader yields next.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
loader (DataLoader): A loader built by 'seeded_dataloader'.
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
Dict[str, Any]: The state of the shuffling generator, of the dataset's
|
|
203
|
+
sampling generators in this process and, for persistent workers,
|
|
204
|
+
of the copies the workers hold.
|
|
205
|
+
"""
|
|
206
|
+
collate = loader.collate_fn
|
|
207
|
+
return {
|
|
208
|
+
"generator": (
|
|
209
|
+
loader.generator.get_state() if loader.generator is not None else None
|
|
210
|
+
),
|
|
211
|
+
"holders": [get_generator_state(h.rng) for h in _rng_holders(loader.dataset)],
|
|
212
|
+
"workers": (
|
|
213
|
+
collate.snapshot() if isinstance(collate, WorkerRandomState) else None
|
|
214
|
+
),
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def prime_loader_workers(loader: DataLoader, state: Dict[str, Any]) -> bool:
|
|
219
|
+
"""Give a loader's persistent workers the state saved by 'loader_random_state'.
|
|
220
|
+
|
|
221
|
+
Must run before the workers start, that is before the loader is first
|
|
222
|
+
iterated.
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
loader (DataLoader): The loader of the resumed trial.
|
|
226
|
+
state (Dict[str, Any]): The saved state.
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
bool: False when the workers' state was needed but could not be saved
|
|
230
|
+
or restored, so that the resumed epochs will draw other samples.
|
|
231
|
+
"""
|
|
232
|
+
collate = loader.collate_fn
|
|
233
|
+
if not isinstance(collate, WorkerRandomState):
|
|
234
|
+
return True
|
|
235
|
+
if state.get("workers") is None or len(state["workers"]) != loader.num_workers:
|
|
236
|
+
return False
|
|
237
|
+
collate.prime(state["workers"], loader)
|
|
238
|
+
return True
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def restore_loader_random_state(loader: DataLoader, state: Dict[str, Any]) -> None:
|
|
242
|
+
"""Restore the shuffling and sampling state saved by 'loader_random_state'.
|
|
243
|
+
|
|
244
|
+
Args:
|
|
245
|
+
loader (DataLoader): The loader of the resumed trial.
|
|
246
|
+
state (Dict[str, Any]): The saved state.
|
|
247
|
+
"""
|
|
248
|
+
if loader.generator is not None and state.get("generator") is not None:
|
|
249
|
+
loader.generator.set_state(state["generator"])
|
|
250
|
+
for holder, saved in zip(_rng_holders(loader.dataset), state.get("holders", [])):
|
|
251
|
+
set_generator_state(holder.rng, saved)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def seeded_dataloader(
|
|
255
|
+
dataset: Dataset,
|
|
256
|
+
batch_size: int,
|
|
257
|
+
shuffle: bool,
|
|
258
|
+
seed: int,
|
|
259
|
+
**kwargs: Any,
|
|
260
|
+
) -> DataLoader:
|
|
261
|
+
"""Wrap a dataset in a DataLoader whose shuffling and sampling are reproducible.
|
|
262
|
+
|
|
263
|
+
Every entity builds its loaders the same way, so the generator and the worker
|
|
264
|
+
seeding live here rather than being repeated at each call site, where one copy
|
|
265
|
+
could silently drift from the rest.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
dataset (Dataset): The dataset to iterate.
|
|
269
|
+
batch_size (int): The batch size.
|
|
270
|
+
shuffle (bool): Whether to shuffle the data.
|
|
271
|
+
seed (int): The seed that makes an epoch reproducible.
|
|
272
|
+
**kwargs (Any): Additional keyword arguments for the DataLoader.
|
|
273
|
+
|
|
274
|
+
Returns:
|
|
275
|
+
DataLoader: The seeded loader.
|
|
276
|
+
"""
|
|
277
|
+
generator = torch.Generator()
|
|
278
|
+
generator.manual_seed(seed)
|
|
279
|
+
|
|
280
|
+
# Persistent workers carry their sampling state across epochs, so it is
|
|
281
|
+
# tracked for a trial that is paused and resumed.
|
|
282
|
+
num_workers = kwargs.get("num_workers", 0)
|
|
283
|
+
if num_workers > 0 and kwargs.get("persistent_workers", False):
|
|
284
|
+
kwargs["collate_fn"] = WorkerRandomState(kwargs.get("collate_fn"), num_workers)
|
|
285
|
+
|
|
286
|
+
return DataLoader(
|
|
287
|
+
dataset,
|
|
288
|
+
batch_size=batch_size,
|
|
289
|
+
shuffle=shuffle,
|
|
290
|
+
worker_init_fn=seed_worker,
|
|
291
|
+
generator=generator,
|
|
292
|
+
**kwargs,
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def map_to_index_space(
|
|
297
|
+
data: DataFrame[Any],
|
|
298
|
+
user_label: str,
|
|
299
|
+
item_label: str,
|
|
300
|
+
user_mapping: dict,
|
|
301
|
+
item_mapping: dict,
|
|
302
|
+
keep: Optional[list] = None,
|
|
303
|
+
) -> DataFrame[Any]:
|
|
304
|
+
"""Attach the user and item indices to a frame of raw interactions.
|
|
305
|
+
|
|
306
|
+
The two joins are inner ones on purpose: a row naming a user or an item the
|
|
307
|
+
mappings do not know is outside the catalogue the experiment was built on and
|
|
308
|
+
is dropped. That rule is the reason this lives in one place - the row-oriented
|
|
309
|
+
entities each used to carry their own copy of it, and a copy is a chance for
|
|
310
|
+
the two to disagree about which rows exist.
|
|
311
|
+
|
|
312
|
+
A join does not promise to keep the rows in their input order (polars does
|
|
313
|
+
not), so each row also carries its position in the input, ``ROW_INDEX``.
|
|
314
|
+
Sorting on it after the indices keeps repeated (user, item) rows in file
|
|
315
|
+
order, which is what the 'first' and 'last' duplicate policies mean.
|
|
316
|
+
|
|
317
|
+
Args:
|
|
318
|
+
data (DataFrame[Any]): The raw interactions.
|
|
319
|
+
user_label (str): The name of the user column.
|
|
320
|
+
item_label (str): The name of the item column.
|
|
321
|
+
user_mapping (dict): Mapping of user ID -> user index.
|
|
322
|
+
item_mapping (dict): Mapping of item ID -> item index.
|
|
323
|
+
keep (Optional[list]): Columns to carry through in addition to the
|
|
324
|
+
indices. Left out, every column of the input is kept.
|
|
325
|
+
|
|
326
|
+
Returns:
|
|
327
|
+
DataFrame[Any]: The frame with the index and row position columns attached.
|
|
328
|
+
"""
|
|
329
|
+
namespace = nw.get_native_namespace(data)
|
|
330
|
+
umap_df = nw.from_dict(
|
|
331
|
+
{
|
|
332
|
+
user_label: list(user_mapping.keys()),
|
|
333
|
+
USER_INDEX: list(user_mapping.values()),
|
|
334
|
+
},
|
|
335
|
+
native_namespace=namespace,
|
|
336
|
+
)
|
|
337
|
+
imap_df = nw.from_dict(
|
|
338
|
+
{
|
|
339
|
+
item_label: list(item_mapping.keys()),
|
|
340
|
+
ITEM_INDEX: list(item_mapping.values()),
|
|
341
|
+
},
|
|
342
|
+
native_namespace=namespace,
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
mapped = (
|
|
346
|
+
data.with_row_index(ROW_INDEX)
|
|
347
|
+
.join(umap_df, on=user_label, how="inner")
|
|
348
|
+
.join(imap_df, on=item_label, how="inner")
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
if keep is None:
|
|
352
|
+
return mapped
|
|
353
|
+
return mapped.select(
|
|
354
|
+
[nw.col(c) for c in (*keep, USER_INDEX, ITEM_INDEX, ROW_INDEX)]
|
|
355
|
+
)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from typing import Any, Dict, FrozenSet, Iterable
|
|
2
|
+
|
|
3
|
+
# The keyword arguments WarpRec passes to every model it builds, restores or
|
|
4
|
+
# estimates, next to the stash.
|
|
5
|
+
MODEL_ARGUMENTS: FrozenSet[str] = frozenset(
|
|
6
|
+
{
|
|
7
|
+
"name",
|
|
8
|
+
"params",
|
|
9
|
+
"info",
|
|
10
|
+
"interactions",
|
|
11
|
+
"transactions",
|
|
12
|
+
"knowledge",
|
|
13
|
+
"multimodal",
|
|
14
|
+
"sessions",
|
|
15
|
+
"seed",
|
|
16
|
+
"block_size",
|
|
17
|
+
"chunk_size",
|
|
18
|
+
"checkpoint",
|
|
19
|
+
"strict",
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
# The keyword arguments the evaluator passes to every metric, next to the stash.
|
|
24
|
+
METRIC_ARGUMENTS: FrozenSet[str] = frozenset(
|
|
25
|
+
{
|
|
26
|
+
"k",
|
|
27
|
+
"num_users",
|
|
28
|
+
"num_items",
|
|
29
|
+
"item_interactions",
|
|
30
|
+
"item_indices",
|
|
31
|
+
"train_matrix",
|
|
32
|
+
"feature_lookup",
|
|
33
|
+
"user_cluster",
|
|
34
|
+
"item_cluster",
|
|
35
|
+
"propensity",
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def check_stash(
|
|
41
|
+
stash: Dict[str, Any], reserved: Iterable[str], receiver: str
|
|
42
|
+
) -> Dict[str, Any]:
|
|
43
|
+
"""Refuse a stash entry named like an argument WarpRec passes itself.
|
|
44
|
+
|
|
45
|
+
The stash is passed as keyword arguments next to WarpRec's own, so an entry
|
|
46
|
+
with one of their names would replace it, or make the call fail with a
|
|
47
|
+
message that does not mention the stash.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
stash (Dict[str, Any]): The stash.
|
|
51
|
+
reserved (Iterable[str]): The arguments WarpRec passes to the receiver.
|
|
52
|
+
receiver (str): What the stash is passed to, e.g. 'model' or 'metric'.
|
|
53
|
+
|
|
54
|
+
Returns:
|
|
55
|
+
Dict[str, Any]: The stash, unchanged.
|
|
56
|
+
|
|
57
|
+
Raises:
|
|
58
|
+
ValueError: If a stash entry has the name of a reserved argument.
|
|
59
|
+
"""
|
|
60
|
+
reserved = set(reserved)
|
|
61
|
+
taken = sorted(key for key in stash if key in reserved)
|
|
62
|
+
if taken:
|
|
63
|
+
raise ValueError(
|
|
64
|
+
f"The stash entry {', '.join(repr(key) for key in taken)} has the "
|
|
65
|
+
f"name of an argument WarpRec passes to every {receiver} itself, so "
|
|
66
|
+
"one would replace the other. Rename the entry; the names WarpRec "
|
|
67
|
+
f"uses are {sorted(reserved)}."
|
|
68
|
+
)
|
|
69
|
+
return stash
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import time
|
|
2
2
|
from typing import List, Dict, Optional, Set, Any, Tuple
|
|
3
3
|
|
|
4
|
+
import numpy as np
|
|
4
5
|
import torch
|
|
5
6
|
from torch import Tensor
|
|
6
7
|
from torch.utils.data import DataLoader
|
|
7
8
|
from scipy.sparse import csr_matrix
|
|
8
9
|
|
|
9
10
|
from warprec.data import Dataset
|
|
11
|
+
from warprec.data.stash import METRIC_ARGUMENTS, check_stash
|
|
10
12
|
from warprec.data.ranking import (
|
|
11
13
|
cold_item_candidates,
|
|
12
14
|
mask_seen_in_context,
|
|
@@ -131,8 +133,13 @@ class Evaluator:
|
|
|
131
133
|
"user_cluster": user_cluster,
|
|
132
134
|
"item_cluster": item_cluster,
|
|
133
135
|
"propensity": propensity,
|
|
134
|
-
**additional_data,
|
|
135
136
|
}
|
|
137
|
+
# The additional data (the dataset's stash) is passed next to these and
|
|
138
|
+
# to the cutoff, so a key of theirs would replace one of WarpRec's.
|
|
139
|
+
check_stash(
|
|
140
|
+
additional_data, {"k", *self.common_params, *METRIC_ARGUMENTS}, "metric"
|
|
141
|
+
)
|
|
142
|
+
self.common_params.update(additional_data)
|
|
136
143
|
self._init_metrics(metric_list, complex_metrics)
|
|
137
144
|
|
|
138
145
|
def _init_metrics(
|
|
@@ -542,6 +549,11 @@ class Evaluator:
|
|
|
542
549
|
def compute_results(self) -> Dict[int, Dict[str, float | Tensor]]:
|
|
543
550
|
"""The method to retrieve computed results in dictionary format.
|
|
544
551
|
|
|
552
|
+
Every value is either a tensor with one entry per user index, for a
|
|
553
|
+
metric averaged over users (NaN for a user it does not apply to), or a
|
|
554
|
+
Python float, for a global value. A 0-d tensor or another number a
|
|
555
|
+
metric returns is turned into a float.
|
|
556
|
+
|
|
545
557
|
Returns:
|
|
546
558
|
Dict[int, Dict[str, float | Tensor]]: The dictionary containing the results.
|
|
547
559
|
"""
|
|
@@ -550,9 +562,38 @@ class Evaluator:
|
|
|
550
562
|
results[k] = {}
|
|
551
563
|
for metric in metric_instances:
|
|
552
564
|
metric_result = metric.compute()
|
|
553
|
-
|
|
565
|
+
for name, value in metric_result.items():
|
|
566
|
+
results[k][name] = self._as_result(name, value)
|
|
554
567
|
return results
|
|
555
568
|
|
|
569
|
+
def _as_result(self, name: str, value: Any) -> float | Tensor:
|
|
570
|
+
"""Bring a metric's value to one of the two shapes results have.
|
|
571
|
+
|
|
572
|
+
Args:
|
|
573
|
+
name (str): The key the metric reports the value under.
|
|
574
|
+
value (Any): The value.
|
|
575
|
+
|
|
576
|
+
Returns:
|
|
577
|
+
float | Tensor: A tensor with one value per user, or a float.
|
|
578
|
+
|
|
579
|
+
Raises:
|
|
580
|
+
ValueError: If the value is neither a number nor a per-user tensor.
|
|
581
|
+
"""
|
|
582
|
+
num_users = self.common_params["num_users"]
|
|
583
|
+
if isinstance(value, Tensor):
|
|
584
|
+
if value.dim() == 0:
|
|
585
|
+
return float(value.item())
|
|
586
|
+
if value.dim() == 1 and value.numel() == num_users:
|
|
587
|
+
return value
|
|
588
|
+
elif isinstance(value, (int, float, np.number)) and not isinstance(value, bool):
|
|
589
|
+
return float(value)
|
|
590
|
+
shape = tuple(value.shape) if isinstance(value, Tensor) else None
|
|
591
|
+
raise ValueError(
|
|
592
|
+
f"The metric result '{name}' is a {type(value).__name__}"
|
|
593
|
+
f"{f' of shape {shape}' if shape is not None else ''}. A metric "
|
|
594
|
+
f"reports a tensor with one value per user ({num_users}) or a number."
|
|
595
|
+
)
|
|
596
|
+
|
|
556
597
|
def _retrieve_sequences_for_user(
|
|
557
598
|
self, dataset: Dataset, user_indices: List[int], max_seq_len: int
|
|
558
599
|
) -> Tuple[Tensor, Tensor]:
|
|
@@ -44,7 +44,7 @@ class AUC(BaseMetric):
|
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
def update(self, preds: Tensor, **kwargs: Any):
|
|
47
|
-
target =
|
|
47
|
+
target = self.block(kwargs, "binary_relevance", preds)
|
|
48
48
|
|
|
49
49
|
# Compute area and positives
|
|
50
50
|
area, positives = self.compute_area_stats(preds, target, self.num_items)
|
|
@@ -69,8 +69,7 @@ class F1(TopKMetric):
|
|
|
69
69
|
# Update needed blocks to be the union of the blocks
|
|
70
70
|
# of the two metrics
|
|
71
71
|
self._REQUIRED_COMPONENTS = (
|
|
72
|
-
self.metric_instance_1.
|
|
73
|
-
| self.metric_instance_2._REQUIRED_COMPONENTS
|
|
72
|
+
self.metric_instance_1.components | self.metric_instance_2.components
|
|
74
73
|
)
|
|
75
74
|
|
|
76
75
|
def update(self, preds: Tensor, user_indices: Tensor, **kwargs: Any):
|
|
@@ -40,8 +40,8 @@ class GAUC(UserAverageTopKMetric):
|
|
|
40
40
|
self.num_items = num_items
|
|
41
41
|
|
|
42
42
|
def unpack_inputs(self, preds: Tensor, **kwargs: Any) -> Tuple[Tensor, Tensor, Any]:
|
|
43
|
-
target =
|
|
44
|
-
users =
|
|
43
|
+
target = self.block(kwargs, "binary_relevance", preds)
|
|
44
|
+
users = self.block(kwargs, "valid_users", preds)
|
|
45
45
|
return target, users, None
|
|
46
46
|
|
|
47
47
|
def compute_scores(
|
|
@@ -28,12 +28,9 @@ class nDCG(UserAverageTopKMetric):
|
|
|
28
28
|
def unpack_inputs(
|
|
29
29
|
self, preds: Tensor, **kwargs: Any
|
|
30
30
|
) -> Tuple[Tensor, Tensor, Tensor]:
|
|
31
|
-
target =
|
|
32
|
-
users =
|
|
33
|
-
top_k_rel = kwargs.
|
|
34
|
-
f"top_{self.k}_discounted_relevance",
|
|
35
|
-
self.top_k_relevance(preds, target, self.k),
|
|
36
|
-
)
|
|
31
|
+
target = self.block(kwargs, "discounted_relevance", preds)
|
|
32
|
+
users = self.block(kwargs, "valid_users", preds)
|
|
33
|
+
top_k_rel = self.block(kwargs, f"top_{self.k}_discounted_relevance", preds)
|
|
37
34
|
return target, users, top_k_rel
|
|
38
35
|
|
|
39
36
|
def compute_scores(
|