Skip to content
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
15 changes: 6 additions & 9 deletions smdebug/trials/trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,14 @@ def tensors(self, *, step=None, mode=ModeKeys.GLOBAL, regex=None, collection=Non

if regex is None and collection is None:
return sorted(list(ts))
elif regex is not None and collection is not None:
raise ValueError("Only one of `regex` or `collection` can be passed to this method")
else:
xs = set()
if regex is not None:
xs.update(self._tensors_matching_regex(regex))
if collection is not None:
collection_tensors_saved = set(self._tensors.keys()).intersection(
self._tensors_in_collection(collection)
)
xs.update(collection_tensors_saved)

return sorted(list(ts.intersection(xs)))
xs = set(self._tensors.keys()).intersection(self._tensors_in_collection(collection))
else:
xs = self._tensors_matching_regex(regex)
return sorted(list(ts.intersection(xs)))

def _tensors_for_step(self, step, mode=ModeKeys.GLOBAL) -> list:
step = self._mode_to_global[mode][step] if mode != ModeKeys.GLOBAL else step
Expand Down
6 changes: 6 additions & 0 deletions tests/analysis/trials/test_tensors_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ def test_tensors(out_dir):
assert len(tr.tensors(collection="test")) == num_tensors + 2
assert len(tr.tensors(collection=tr.collection("test"))) == num_tensors + 2

try:
tr.tensors(collection=tr.collection("test"), regex="a")
assert False
except ValueError:
pass

Comment on lines +51 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use

with pytest.raises(ValueError):
   tr.tensors(...)


def test_mode_data():
run_id = "trial_" + datetime.now().strftime("%Y%m%d-%H%M%S%f")
Expand Down