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

Use encoder/decoder call directly #2366

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
use encoder/decoder call directly
  • Loading branch information
AnnaKwa committed Nov 8, 2023
commit 068bb7a7cd5f8d9ed9cfb05862b925c4128a3f76
4 changes: 2 additions & 2 deletions external/fv3fit/fv3fit/reservoir/transformers/autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def call(self, x: ArrayLike) -> tf.Tensor:

def encode(self, x: Sequence[ArrayLike]) -> ArrayLike:
x = _ensure_all_items_have_sample_dim(x)
return self.encoder.predict(x)
return self.encoder(x)

def decode(self, latent_x: ArrayLike) -> Sequence[ArrayLike]:
return to_list(self.decoder.predict(latent_x))
return to_list(self.decoder(latent_x))

def dump(self, path: str) -> None:
with put_dir(path) as path:
Expand Down
4 changes: 2 additions & 2 deletions external/fv3fit/fv3fit/reservoir/transformers/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def decode_columns(
leading_shape = encoded_output.shape[:-1]
encoded_output = encoded_output.reshape(-1, feature_size)
decoded = transformer.decode(encoded_output)
var_arrays = [arr.reshape(*leading_shape, -1) for arr in decoded]
var_arrays = [tf.reshape(arr, (*leading_shape, -1)) for arr in decoded]
return var_arrays


Expand All @@ -138,4 +138,4 @@ def encode_columns(
original_sample_shape = input_arrs[0].shape[:-1]
reshaped = [stack_array_preserving_last_dim(var) for var in input_arrs]
encoded_reshaped = transformer.encode(reshaped)
return encoded_reshaped.reshape(*original_sample_shape, -1)
return tf.reshape(encoded_reshaped, (*original_sample_shape, -1))