Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert directory fbcode/hammer to use the Ruff Formatter #142

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion generative_recommenders/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def _truncate_or_pad_seq(


class MultiFileDatasetV2(DatasetV2, torch.utils.data.Dataset):

def __init__(
self,
file_prefix: str,
Expand Down
12 changes: 8 additions & 4 deletions generative_recommenders/data/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,14 @@ def preprocess_rating(self) -> int:
return num_unique_items


def get_common_preprocessors() -> Dict[
str,
Union[AmazonDataProcessor, MovielensDataProcessor, MovielensSyntheticDataProcessor],
]:
def get_common_preprocessors() -> (
Dict[
str,
Union[
AmazonDataProcessor, MovielensDataProcessor, MovielensSyntheticDataProcessor
],
]
):
ml_1m_dp = MovielensDataProcessor( # pyre-ignore [45]
"http://files.grouplens.org/datasets/movielens/ml-1m.zip",
"tmp/movielens1m.zip",
Expand Down
6 changes: 3 additions & 3 deletions generative_recommenders/indexing/candidate_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@


class TopKModule(torch.nn.Module):

@abc.abstractmethod
def forward(
self,
Expand All @@ -44,7 +43,6 @@ def forward(


class CandidateIndex(object):

def __init__(
self,
ids: torch.Tensor,
Expand Down Expand Up @@ -226,7 +224,9 @@ def get_top_k_outputs(
else self.embeddings
)
top_k_embeddings = batch_gather_embeddings(
rowwise_indices=top_k_indices, embeddings=expanded_embeddings # pyre-ignore[10]
# pyre-fixme[10]: Name `top_k_indices` is used but not defined.
rowwise_indices=top_k_indices,
embeddings=expanded_embeddings, # pyre-ignore[10]
)
else:
top_k_embeddings = None
Expand Down
2 changes: 0 additions & 2 deletions generative_recommenders/indexing/mips_top_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class MIPSTopKModule(TopKModule):

def __init__(
self,
item_embeddings: torch.Tensor,
Expand All @@ -40,7 +39,6 @@ def __init__(


class MIPSBruteForceTopK(MIPSTopKModule):

def __init__(
self,
item_embeddings: torch.Tensor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@


class NegativesSampler(torch.nn.Module):

def __init__(self, l2_norm: bool, l2_norm_eps: float) -> None:
super().__init__()

Expand Down Expand Up @@ -72,7 +71,6 @@ def forward(


class LocalNegativesSampler(NegativesSampler):

def __init__(
self,
num_items: int,
Expand Down Expand Up @@ -124,7 +122,6 @@ def forward(


class InBatchNegativesSampler(NegativesSampler):

def __init__(
self,
l2_norm: bool,
Expand Down Expand Up @@ -205,7 +202,6 @@ def forward(


class AutoregressiveLoss(torch.nn.Module):

@abc.abstractmethod
def jagged_forward(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class EmbeddingModule(torch.nn.Module):

@abc.abstractmethod
def debug_str(self) -> str:
pass
Expand All @@ -38,7 +37,6 @@ def item_embedding_dim(self) -> int:


class LocalEmbeddingModule(EmbeddingModule):

def __init__(
self,
num_items: int,
Expand Down Expand Up @@ -74,7 +72,6 @@ def item_embedding_dim(self) -> int:


class CategoricalEmbeddingModule(EmbeddingModule):

def __init__(
self,
num_items: int,
Expand Down
3 changes: 0 additions & 3 deletions generative_recommenders/modeling/sequential/hstu.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@


class RelativeAttentionBiasModule(torch.nn.Module):

@abc.abstractmethod
def forward(
self,
Expand All @@ -63,7 +62,6 @@ def forward(


class RelativePositionalBias(RelativeAttentionBiasModule):

def __init__(self, max_seq_len: int) -> None:
super().__init__()

Expand Down Expand Up @@ -445,7 +443,6 @@ def forward( # pyre-ignore [3]


class HSTUJagged(torch.nn.Module):

def __init__(
self,
modules: List[SequentialTransductionUnitJagged],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


class InputFeaturesPreprocessorModule(torch.nn.Module):

@abc.abstractmethod
def debug_str(self) -> str:
pass
Expand All @@ -43,7 +42,6 @@ def forward(
class LearnablePositionalEmbeddingInputFeaturesPreprocessor(
InputFeaturesPreprocessorModule
):

def __init__(
self,
max_sequence_len: int,
Expand Down Expand Up @@ -94,7 +92,6 @@ def forward(
class LearnablePositionalEmbeddingRatedInputFeaturesPreprocessor(
InputFeaturesPreprocessorModule
):

def __init__(
self,
max_sequence_len: int,
Expand Down Expand Up @@ -156,7 +153,6 @@ def forward(


class CombinedItemAndRatingInputFeaturesPreprocessor(InputFeaturesPreprocessorModule):

def __init__(
self,
max_sequence_len: int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@


class SampledSoftmaxLoss(AutoregressiveLoss):

def __init__(
self,
num_to_sample: int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


class OutputPostprocessorModule(torch.nn.Module):

@abc.abstractmethod
def debug_str(self) -> str:
pass
Expand All @@ -35,7 +34,6 @@ def forward(


class L2NormEmbeddingPostprocessor(OutputPostprocessorModule):

def __init__(
self,
embedding_dim: int,
Expand All @@ -60,7 +58,6 @@ def forward(


class LayerNormEmbeddingPostprocessor(OutputPostprocessorModule):

def __init__(
self,
embedding_dim: int,
Expand Down
9 changes: 8 additions & 1 deletion generative_recommenders/modeling/sequential/sasrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ def predict(
batch_id: Optional[int] = None,
) -> torch.Tensor:
return self.interaction(
self.encode(past_ids, past_ratings, past_timestamps, next_timestamps), # pyre-ignore [6]
self.encode(
# pyre-fixme[6]: For 4th argument expected `Dict[str, Tensor]` but
# got `Tensor`.
past_ids,
past_ratings,
past_timestamps,
next_timestamps,
), # pyre-ignore [6]
target_ids,
) # [B, X]
13 changes: 6 additions & 7 deletions generative_recommenders/modeling/similarity/mol.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
# pyre-unsafe

"""
Implements MoL (Mixture-of-Logits) in
Implements MoL (Mixture-of-Logits) in
Revisiting Neural Retrieval on Accelerators (https://arxiv.org/abs/2306.04039, KDD'23).
"""

from typing import Callable, Dict, Optional, Tuple

import torch
Expand All @@ -29,7 +30,6 @@


class SoftmaxDropout(torch.nn.Module):

def __init__(
self,
dropout_rate: float,
Expand All @@ -51,7 +51,6 @@ def forward(


class SoftmaxDropoutCombiner(torch.nn.Module):

def __init__(
self,
dropout_rate: float,
Expand Down Expand Up @@ -110,7 +109,6 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:


class TauFn(torch.nn.Module):

def __init__(
self,
alpha: float,
Expand All @@ -132,7 +130,6 @@ def forward(


class GeGLU(torch.nn.Module):

def __init__(
self,
in_features: int,
Expand Down Expand Up @@ -201,7 +198,6 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:


class MoLGatingFn(torch.nn.Module):

def __init__(
self,
num_logits: int,
Expand Down Expand Up @@ -291,7 +287,10 @@ def forward(
if self._item_only_partial_module is not None:
if item_sideinfo is not None:
item_embeddings = torch.cat([item_embeddings, item_sideinfo], dim=-1)
item_partial_inputs = self._item_only_partial_module(item_embeddings) # pyre-ignore [29]
# pyre-fixme[29]: `Optional[Module]` is not a function.
item_partial_inputs = self._item_only_partial_module(
item_embeddings
) # pyre-ignore [29]
if self._ci_partial_module is not None:
if self._combine_item_sideinfo_into_ci:
assert item_sideinfo is not None
Expand Down
5 changes: 4 additions & 1 deletion generative_recommenders/modeling/similarity_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def create_mol_interaction_module(
).apply(init_mlp_xavier_weights_zero_bias)
)
),
gating_context_only_partial_fn=lambda input_dim, output_dim: ( # pyre-ignore [6]
# pyre-fixme[6]: For 12th argument expected `Optional[(int, int) -> Module]`
# but got `(input_dim: Any, output_dim: Any) -> Optional[Sequential]`.
gating_context_only_partial_fn=lambda input_dim,
output_dim: ( # pyre-ignore [6]
torch.nn.Sequential(
torch.nn.Linear(
in_features=input_dim,
Expand Down
Loading