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

Symbolic Tensors #47

Open
niccololaurora opened this issue Nov 1, 2024 · 1 comment
Open

Symbolic Tensors #47

niccololaurora opened this issue Nov 1, 2024 · 1 comment

Comments

@niccololaurora
Copy link
Collaborator

The Keras interface works fine but I had to change the Binary Encoding.

TensorFlow’s Graph Mode relies on Symbolic Tensors, which act as placeholders without actual data during initial model checks. When using model.fit, TensorFlow first uses these Symbolic Tensors to traverse and verify the computation graph, ensuring compatibility across all operations. Only after this validation process, when the graph structure is confirmed as sound, does TensorFlow pass real data through the model to perform actual training. This approach allows TensorFlow to optimize and catch issues before handling real inputs.

Therefore, we have the following problems (probably more) when dealing with Symbolic Tensors:

  1. We cannot use NumPy functions on Symbolic Tensors;
  2. We cannot access data contained in Symbolic Tensors (because they are empty);
  3. We cannot iterate over Symbolic Tensors (because they are empty);
  4. We cannot use "if" statements if Symbolic Tensors are involved;

We need to work around these problems by using native TensorFlow functions.
For instance, instead of an "if" statement we must use tf.cond.

However, the issue that I have encountered with the Binary Encoding (which has forced me to redefine this encoding) could be a sign of a deeper problem: we might need to define each encoding (or every other component of the QuantumModel) depending on the frontend that we use.
This is due to the fact that Symbolic Tensors force us to use native TensorFlow functions, that could be not compatible with PyTorch.

@BrunoLiegiBastonLiegi
Copy link
Contributor

You can force eager execution with run_eagerly=True in model.compile https://www.tensorflow.org/api_docs/python/tf/keras/Model#run_eagerly
This is probably not recommended for the sake of pure speed, but we could just do that for those layers that are problematic, at least for the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants