Skip to content
Merged
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
2 changes: 1 addition & 1 deletion tensorflow_gnn/experimental/sampler/beam/accessors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_string_keys(self):
}
layer = sampler.KeyToTfExampleAccessor(
sampler.InMemStringKeyToBytesAccessor(
keys_to_values=table, name='table'
keys_to_values=table, name='table' # pyrefly: ignore[bad-argument-type]
),
features_spec={
's': tf.TensorSpec([], tf.int64),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_sampling_stats(self):
edges_layer = sampler.UniformEdgesSampler(
sampler.KeyToTfExampleAccessor(
sampler.InMemStringKeyToBytesAccessor(
keys_to_values={b'?': b''}, name='edges'
keys_to_values={b'?': b''}, name='edges' # pyrefly: ignore[bad-argument-type]
),
features_spec={
'#target': tf.TensorSpec([None], tf.string),
Expand Down Expand Up @@ -313,7 +313,7 @@ def test_missing_values(self):
edges_layer = sampler.UniformEdgesSampler(
sampler.KeyToTfExampleAccessor(
sampler.InMemStringKeyToBytesAccessor(
keys_to_values={b'?': b''}, name='edges'
keys_to_values={b'?': b''}, name='edges' # pyrefly: ignore[bad-argument-type]
),
features_spec={
'#target': tf.TensorSpec([None], tf.int64),
Expand Down Expand Up @@ -437,7 +437,7 @@ def test_edge_features(self, feature_name: str, shape: List[int]):
edges_layer = sampler.UniformEdgesSampler(
sampler.KeyToTfExampleAccessor(
sampler.InMemStringKeyToBytesAccessor(
keys_to_values={b'?': b''}, name='edges'
keys_to_values={b'?': b''}, name='edges' # pyrefly: ignore[bad-argument-type]
),
features_spec={
'#target': tf.TensorSpec([None], tf.string),
Expand Down Expand Up @@ -504,7 +504,7 @@ def test_ragged_features(self):
edges_layer = sampler.UniformEdgesSampler(
sampler.KeyToTfExampleAccessor(
sampler.InMemStringKeyToBytesAccessor(
keys_to_values={b'?': b''}, name='edges'
keys_to_values={b'?': b''}, name='edges' # pyrefly: ignore[bad-argument-type]
),
features_spec={
'neighbors': tf.TensorSpec([None], tf.int64),
Expand Down
16 changes: 8 additions & 8 deletions tensorflow_gnn/experimental/sampler/beam/executor_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ def process(
self, inputs: Tuple[bytes, Tuple[str, Values]]
) -> Iterator[Tuple[bytes, Values]]:
example_id, (stage_id, values) = inputs
inputs = []
inputs = [] # pyrefly: ignore[bad-assignment]
for matcher in self._stage.input_matchers:
assert matcher.stage_id == stage_id, example_id
inputs.append(values[matcher.output_index])
yield (example_id, inputs)
inputs.append(values[matcher.output_index]) # pyrefly: ignore[missing-attribute]
yield (example_id, inputs) # pyrefly: ignore[invalid-yield]

@beam_typehints.with_input_types(
Tuple[ExampleId, Iterable[Tuple[str, Values]]]
Expand All @@ -289,11 +289,11 @@ def process(
) -> Iterator[Tuple[bytes, Values]]:
example_id, outputs = inputs
outputs = dict(outputs)
inputs = []
inputs = [] # pyrefly: ignore[bad-assignment]
for matcher in self._stage.input_matchers:
values = outputs[matcher.stage_id]
inputs.append(values[matcher.output_index])
yield (example_id, inputs)
inputs.append(values[matcher.output_index]) # pyrefly: ignore[missing-attribute]
yield (example_id, inputs) # pyrefly: ignore[invalid-yield]

def __init__(self, stage: pb.Stage):
self._stage = stage
Expand Down Expand Up @@ -364,11 +364,11 @@ def __init__(
def expand(
self, inputs: Tuple[Dict[str, PValues], Dict[str, PFeed]]
) -> PValues:
inputs, feeds = inputs
inputs, feeds = inputs # pyrefly: ignore[bad-assignment]
return _execute(
self._eval_dag,
self._layers,
inputs,
inputs, # pyrefly: ignore[bad-argument-type]
feeds=feeds,
artifacts_path=self._artifacts_path,
)
Expand Down
8 changes: 4 additions & 4 deletions tensorflow_gnn/experimental/sampler/beam/executor_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,16 @@ def test_any_composite(self):

i = tf.keras.Input([2], name='input')
o = i
o = tf.keras.layers.Lambda(tf.sparse.from_dense)(o)
o = tf.keras.layers.Lambda(tf.math.negative)(o)
o = tf.keras.layers.Lambda(tf.sparse.from_dense)(o) # pyrefly: ignore[not-callable]
o = tf.keras.layers.Lambda(tf.math.negative)(o) # pyrefly: ignore[not-callable]
# Add identity composite layer which splits eval data on five pieces:
# <input> => <to negative sparse> => identity -> <to dense> => output.
o = Identity()(o)
o = Identity()(o) # pyrefly: ignore[not-callable]

def fn(t):
return tf.sparse.to_dense(t)

o = tf.keras.layers.Lambda(fn)(o)
o = tf.keras.layers.Lambda(fn)(o) # pyrefly: ignore[not-callable]
model = tf.keras.Model(inputs=i, outputs=o)
program, artifacts = sampler.create_program(model)
self.assertLen(program.eval_dag.stages, 5)
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_gnn/experimental/sampler/beam/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def node_features_accessor_factory(
node_set_name: tfgnn.NodeSetName,
) -> sampler.KeyToTfExampleAccessor:
if not graph_schema.node_sets[node_set_name].features:
return None
return None # pyrefly: ignore[bad-return]

node_features = graph_schema.node_sets[node_set_name].features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _get_sampling_model(self, ids_dtype) -> tf.keras.Model:
graph_schema.node_sets['a'].description = 'node set b'
graph_schema.edge_sets['a->b'].source = 'a'
graph_schema.edge_sets['a->b'].target = 'b'
graph_schema.edge_sets['a->a'].features['weights'].dtype = 1
graph_schema.edge_sets['a->a'].features['weights'].dtype = 1 # pyrefly: ignore[bad-assignment]

sampling_spec = tfgnn.sampler.SamplingSpec()
sampling_spec.seed_op.op_name = 'seed'
Expand All @@ -57,7 +57,7 @@ def edge_sampler_factory(sampling_op):
self.assertEqual(sampling_op.edge_set_name, 'a->b')
if ids_dtype == tf.string:
accessor = sampler.InMemStringKeyToBytesAccessor(
keys_to_values={b'a': b''}
keys_to_values={b'a': b''} # pyrefly: ignore[bad-argument-type]
)
else:
accessor = sampler.InMemIntegerKeyToBytesAccessor(
Expand Down
16 changes: 8 additions & 8 deletions tensorflow_gnn/experimental/sampler/beam/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,21 @@ def parse_tf_example(
`[c.numpy() for c in [*rt.flat_values, *rt.nested_row_lengths()]]`.
"""
if spec.HasField('tensor'):
spec = spec.tensor
spec = spec.tensor # pyrefly: ignore[bad-assignment]
return [
_parse_tf_feature(
example,
name,
get_np_dtype(spec.dtype),
tuple(dim.size for dim in spec.shape.dim),
get_np_dtype(spec.dtype), # pyrefly: ignore[missing-attribute]
tuple(dim.size for dim in spec.shape.dim), # pyrefly: ignore[missing-attribute]
)
]
elif spec.HasField('ragged_tensor'):
spec = spec.ragged_tensor
dtype = get_np_dtype(spec.dtype)
ragged_rank = spec.ragged_rank
row_splits_dtype = get_np_dtype(spec.row_splits_dtype)
shape = tuple(dim.size for dim in spec.shape.dim)
spec = spec.ragged_tensor # pyrefly: ignore[bad-assignment]
dtype = get_np_dtype(spec.dtype) # pyrefly: ignore[missing-attribute]
ragged_rank = spec.ragged_rank # pyrefly: ignore[missing-attribute]
row_splits_dtype = get_np_dtype(spec.row_splits_dtype) # pyrefly: ignore[missing-attribute]
shape = tuple(dim.size for dim in spec.shape.dim) # pyrefly: ignore[missing-attribute]

flat_value = _parse_tf_feature(example, name, dtype, shape[ragged_rank:])

Expand Down
12 changes: 6 additions & 6 deletions tensorflow_gnn/experimental/sampler/beam/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ def test_dense_slice(
limit: int,
expected: np.ndarray,
):
value = [value]
expected = [expected]
actual = utils.ragged_slice(value, start, limit)
value = [value] # pyrefly: ignore[bad-assignment]
expected = [expected] # pyrefly: ignore[bad-assignment]
actual = utils.ragged_slice(value, start, limit) # pyrefly: ignore[bad-argument-type]
tf.nest.map_structure(self.assertAllEqual, actual, expected)

@parameterized.named_parameters([
Expand Down Expand Up @@ -194,9 +194,9 @@ def as_value(r: tf.RaggedTensor) -> List[np.ndarray]:
lambda t: t.numpy(), [r.flat_values, *r.nested_row_lengths()]
)

value = as_value(value)
expected = as_value(expected)
actual = utils.ragged_slice(value, start, limit)
value = as_value(value) # pyrefly: ignore[bad-assignment]
expected = as_value(expected) # pyrefly: ignore[bad-assignment]
actual = utils.ragged_slice(value, start, limit) # pyrefly: ignore[bad-argument-type]
tf.nest.map_structure(self.assertAllEqual, actual, expected)


Expand Down
18 changes: 9 additions & 9 deletions tensorflow_gnn/graph/adjacency.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ def _merge_batch_to_components(
assert isinstance(flat_adj, HyperAdjacency)

def flatten_indices(node_tag_key, index: Field) -> Field:
node_set_name = self.spec._metadata[node_tag_key] # pylint: disable=protected-access
return utils.flatten_indices(index, num_edges_per_example,
num_nodes_per_example[node_set_name])
node_set_name = self.spec._metadata[node_tag_key] # pylint: disable=protected-access # pyrefly: ignore[unsupported-operation]
return utils.flatten_indices(index, num_edges_per_example, # pyrefly: ignore[bad-argument-type]
num_nodes_per_example[node_set_name]) # pyrefly: ignore[bad-argument-type, bad-index]

new_data = {
node_tag_key: flatten_indices(node_tag_key, index)
Expand Down Expand Up @@ -324,7 +324,7 @@ def get_index_specs_dict(

def node_set_name(self, node_set_tag: IncidentNodeTag) -> NodeSetName:
"""Returns a node set name for the given node set tag."""
return self._metadata[_node_tag_to_index_key(node_set_tag)]
return self._metadata[_node_tag_to_index_key(node_set_tag)] # pyrefly: ignore[bad-return, unsupported-operation]

@property
def total_size(self) -> Optional[int]:
Expand Down Expand Up @@ -477,7 +477,7 @@ class AdjacencySpec(HyperAdjacencySpec):
"""A type spec for `tfgnn.Adjacency`."""

@classmethod
def from_incident_node_sets(
def from_incident_node_sets( # pyrefly: ignore[bad-override]
cls,
source_node_set: NodeSetName,
target_node_set: NodeSetName,
Expand Down Expand Up @@ -602,25 +602,25 @@ def check_compatibility(tag_0, name_0, index_0, tag_i, name_i, index_i):

raise ValueError(err_message)

indices = sorted(list(indices.items()), key=lambda i: i[0])
indices = sorted(list(indices.items()), key=lambda i: i[0]) # pyrefly: ignore[bad-assignment]
tag_0, (name_0, index_0) = indices[0]
check_index(tag_0, name_0, index_0)
for tag_i, (name_i, index_i) in indices[1:]:
for tag_i, (name_i, index_i) in indices[1:]: # pyrefly: ignore[bad-index]
check_index(tag_i, name_i, index_i)
check_compatibility(tag_0, name_0, index_0, tag_i, name_i, index_i)

# Apply identity operations to all index tensors to ensure that assertions are
# executed in the graph mode.
if not assert_ops:
result = {
node_tag: (node_set, index) for node_tag, (node_set, index) in indices
node_tag: (node_set, index) for node_tag, (node_set, index) in indices # pyrefly: ignore[not-iterable]
}
else:
assert allow_tf_assertions
with tf.control_dependencies(assert_ops):
result = {
node_tag: (node_set, tf.identity(index))
for node_tag, (node_set, index) in indices
for node_tag, (node_set, index) in indices # pyrefly: ignore[not-iterable]
}

return result
Expand Down
10 changes: 5 additions & 5 deletions tensorflow_gnn/graph/batching_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get_next_state(state: _ScanState,
def exceeds_budget(state: _ScanState,
graph_tensor: gt.GraphTensor) -> tf.Tensor:
budget = _set_min_nodes_per_component(state.budget_left,
min_nodes_per_component)
min_nodes_per_component) # pyrefly: ignore[bad-argument-type]
within_budget = padding_ops.satisfies_size_constraints(graph_tensor, budget)
return tf.math.logical_not(within_budget)

Expand Down Expand Up @@ -631,9 +631,9 @@ def _set_min_nodes_per_component(

return SizeConstraints(
total_num_components=size_constraints.total_num_components,
total_num_nodes=size_constraints.total_num_nodes.copy(),
total_num_edges=size_constraints.total_num_edges.copy(),
min_nodes_per_component=min_nodes_per_component.copy())
total_num_nodes=size_constraints.total_num_nodes.copy(), # pyrefly: ignore[missing-attribute]
total_num_edges=size_constraints.total_num_edges.copy(), # pyrefly: ignore[missing-attribute]
min_nodes_per_component=min_nodes_per_component.copy()) # pyrefly: ignore[missing-attribute]


def _make_room_for_padding(
Expand Down Expand Up @@ -876,4 +876,4 @@ def restored_generator():
yield value

return tf.data.Dataset.from_generator(
restored_generator, output_signature=relaxed_spec)
restored_generator, output_signature=relaxed_spec) # pyrefly: ignore[bad-argument-type]
6 changes: 3 additions & 3 deletions tensorflow_gnn/graph/broadcast_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _broadcast_context(graph_tensor: GraphTensor,
# TODO(b/184021442): cache result.
return utils.repeat(
context_value,
node_or_edge_set.sizes,
node_or_edge_set.sizes, # pyrefly: ignore[bad-argument-type]
repeats_sum_hint=node_or_edge_set.spec.total_size)


Expand Down Expand Up @@ -250,11 +250,11 @@ def broadcast_v2(
for name in edge_set_names]
else:
result = [broadcast_context_to_nodes(graph_tensor, name, **feature_kwargs)
for name in node_set_names]
for name in node_set_names] # pyrefly: ignore[not-iterable]
else:
result = [
broadcast_node_to_edges(graph_tensor, name, from_tag, **feature_kwargs)
for name in edge_set_names]
for name in edge_set_names] # pyrefly: ignore[not-iterable]

if got_sequence_args:
return result
Expand Down
18 changes: 9 additions & 9 deletions tensorflow_gnn/graph/graph_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def from_field_specs(
shape=sizes_shape,
ragged_rank=shape.rank + 1,
dtype=indices_dtype,
row_splits_dtype=indicative_feature_spec.row_splits_dtype)
row_splits_dtype=indicative_feature_spec.row_splits_dtype) # pyrefly: ignore[missing-attribute]
else:
sizes_spec = tf.TensorSpec(shape=sizes_shape, dtype=indices_dtype)

Expand Down Expand Up @@ -1244,9 +1244,9 @@ def edge_set_merge_batch_to_components(edge_set: EdgeSet) -> EdgeSet:
return self.__class__.from_pieces(
context=self.context._merge_batch_to_components(), # pylint: disable=protected-access
node_sets=tf.nest.map_structure(
lambda n: n._merge_batch_to_components(), self.node_sets.copy()), # pylint: disable=protected-access
lambda n: n._merge_batch_to_components(), self.node_sets.copy()), # pylint: disable=protected-access # pyrefly: ignore[missing-attribute]
edge_sets=tf.nest.map_structure(edge_set_merge_batch_to_components,
self.edge_sets.copy()))
self.edge_sets.copy())) # pyrefly: ignore[missing-attribute]

@property
def context(self) -> Context:
Expand Down Expand Up @@ -1363,7 +1363,7 @@ def replace_features(
new_context = self.context.replace_features(context)

if node_sets is None:
new_node_sets = self.node_sets.copy()
new_node_sets = self.node_sets.copy() # pyrefly: ignore[missing-attribute]
else:
not_present = set(node_sets.keys()) - set(self.node_sets.keys())
if not_present:
Expand All @@ -1376,7 +1376,7 @@ def replace_features(
}

if edge_sets is None:
new_edge_sets = self.edge_sets.copy()
new_edge_sets = self.edge_sets.copy() # pyrefly: ignore[missing-attribute]
else:
not_present = set(edge_sets.keys()) - set(self.edge_sets.keys())
if not_present:
Expand Down Expand Up @@ -1778,7 +1778,7 @@ def _fields_and_size_from_fieldorfields(
"""Returns a mapping from a default feature name if needed."""
if isinstance(features, collections.abc.Mapping):
num_entities = tf.stack(
[utils.outer_dimension_size(_get_indicative_feature(features))])
[utils.outer_dimension_size(_get_indicative_feature(features))]) # pyrefly: ignore[bad-argument-type]
elif features is None:
features, num_entities = {}, None
else:
Expand Down Expand Up @@ -1833,11 +1833,11 @@ def homogeneous(
raise ValueError('source and target must be rank-1 dense tensors')

node_features, num_nodes = _fields_and_size_from_fieldorfields(
node_features, HIDDEN_STATE)
node_features, HIDDEN_STATE) # pyrefly: ignore[bad-argument-type]
edge_features, _ = _fields_and_size_from_fieldorfields(
edge_features, HIDDEN_STATE)
edge_features, HIDDEN_STATE) # pyrefly: ignore[bad-argument-type]
context_features, _ = _fields_and_size_from_fieldorfields(
context_features, HIDDEN_STATE)
context_features, HIDDEN_STATE) # pyrefly: ignore[bad-argument-type]

num_edges = tf.shape(source)
node_sizes = (num_nodes if node_set_sizes is None else node_set_sizes)
Expand Down
Loading
Loading