×
1 Choose EITC/EITCA Certificates
2 Learn and take online exams
3 Get your IT skills certified

Confirm your IT skills and competencies under the European IT Certification framework from anywhere in the world fully online.

EITCA Academy

Digital skills attestation standard by the European IT Certification Institute aiming to support Digital Society development

LOG IN TO YOUR ACCOUNT

CREATE AN ACCOUNT FORGOT YOUR PASSWORD?

FORGOT YOUR PASSWORD?

AAH, WAIT, I REMEMBER NOW!

CREATE AN ACCOUNT

ALREADY HAVE AN ACCOUNT?
EUROPEAN INFORMATION TECHNOLOGIES CERTIFICATION ACADEMY - ATTESTING YOUR PROFESSIONAL DIGITAL SKILLS
  • SIGN UP
  • LOGIN
  • INFO

EITCA Academy

EITCA Academy

The European Information Technologies Certification Institute - EITCI ASBL

Certification Provider

EITCI Institute ASBL

Brussels, European Union

Governing European IT Certification (EITC) framework in support of the IT professionalism and Digital Society

  • CERTIFICATES
    • EITCA ACADEMIES
      • EITCA ACADEMIES CATALOGUE<
      • EITCA/CG COMPUTER GRAPHICS
      • EITCA/IS INFORMATION SECURITY
      • EITCA/BI BUSINESS INFORMATION
      • EITCA/KC KEY COMPETENCIES
      • EITCA/EG E-GOVERNMENT
      • EITCA/WD WEB DEVELOPMENT
      • EITCA/AI ARTIFICIAL INTELLIGENCE
    • EITC CERTIFICATES
      • EITC CERTIFICATES CATALOGUE<
      • COMPUTER GRAPHICS CERTIFICATES
      • WEB DESIGN CERTIFICATES
      • 3D DESIGN CERTIFICATES
      • OFFICE IT CERTIFICATES
      • BITCOIN BLOCKCHAIN CERTIFICATE
      • WORDPRESS CERTIFICATE
      • CLOUD PLATFORM CERTIFICATENEW
    • EITC CERTIFICATES
      • INTERNET CERTIFICATES
      • CRYPTOGRAPHY CERTIFICATES
      • BUSINESS IT CERTIFICATES
      • TELEWORK CERTIFICATES
      • PROGRAMMING CERTIFICATES
      • DIGITAL PORTRAIT CERTIFICATE
      • WEB DEVELOPMENT CERTIFICATES
      • DEEP LEARNING CERTIFICATESNEW
    • CERTIFICATES FOR
      • EU PUBLIC ADMINISTRATION
      • TEACHERS AND EDUCATORS
      • IT SECURITY PROFESSIONALS
      • GRAPHICS DESIGNERS & ARTISTS
      • BUSINESSMEN AND MANAGERS
      • BLOCKCHAIN DEVELOPERS
      • WEB DEVELOPERS
      • CLOUD AI EXPERTSNEW
  • FEATURED
  • SUBSIDY
  • HOW IT WORKS
  •   IT ID
  • ABOUT
  • CONTACT
  • MY ORDER
    Your current order is empty.
EITCIINSTITUTE
CERTIFIED

What could be a `tf.print` value of tensors during the execution of a computational graph?

by Humberto Gonçalves / Tuesday, 12 May 2026 / Published in Artificial Intelligence, EITC/AI/GCML Google Cloud Machine Learning, Google tools for Machine Learning, Printing statements in TensorFlow

The `tf.print` operation in TensorFlow is a highly practical debugging utility, particularly relevant when working with computational graphs, whether in eager or graph execution mode. Understanding the output or the values presented by `tf.print` during the execution of a computational graph is grounded in how TensorFlow manages computation and data flow within its architecture.

Context of `tf.print` in TensorFlow

TensorFlow, prior to version 2.x, predominantly employed graph execution, where operations were first composed into a static computational graph and subsequently executed within a session. Even in modern TensorFlow, despite the shift toward eager execution by default, graph execution remains central for deployment, optimization, and compatibility with various APIs such as `tf.function`. In graph mode, operations do not execute immediately. Instead, they are added as nodes to the graph, and their actual computation (including tensor values) occurs when the graph is run.

Debugging in this context is nontrivial. Standard Python print statements do not capture the dynamic runtime values of tensors within the graph, as the tensors are symbolic references until the graph is executed. This is where `tf.print` becomes indispensable.

Behavior and Output of `tf.print`

The `tf.print` operation is a TensorFlow op that prints the values of tensors at runtime—during the execution of the graph. Its syntax is:

python
tf.print(*inputs, output_stream=None, summarize=-1, sep=' ', end='\n', name=None)

When the graph executes and the node containing `tf.print` is run, the operation evaluates its inputs, prints their values to the standard output (or another stream, if specified), and returns no output tensor (unlike Python’s `print`, which returns `None`).

Example:
python
import tensorflow as tf

a = tf.constant([1, 2, 3])
b = tf.constant([4, 5, 6])
c = a + b
tf.print("Sum of a and b:", c)

In eager mode, this immediately prints:

Sum of a and b: [5 7 9]

In graph mode (e.g., inside a `@tf.function`), the print statement will execute when the function is called, not during the function’s definition.

Graph Mode Example:
python
@tf.function
def add_and_print():
    a = tf.constant([1, 2, 3])
    b = tf.constant([4, 5, 6])
    c = a + b
    tf.print("Sum of a and b:", c)
    return c

result = add_and_print()

When `add_and_print()` is invoked, the following is printed:

{{EJS17}}

Value of the Output

The value displayed by `tf.print` corresponds to the runtime, concrete value of the tensor at that point in the computational graph. This value is the result of all preceding computations, including any operations, variable assignments, or data transformations leading to the tensor being printed. - For scalar tensors: The printed value is the scalar value itself. - For vector or higher-dimensional tensors: The printed value is the array, possibly summarized depending on the `summarize` argument.
Example: Printing Shapes and Values
python
x = tf.constant([[1, 2], [3, 4]])
tf.print("Shape:", tf.shape(x), "Values:", x)

This prints:

Shape: [2 2] Values: [[1 2]
 [3 4]]

The printed shape `[2 2]` and the values `[[1 2], [3 4]]` are the actual runtime values of the respective tensors.

Didactic Value: Understanding Data Flow and Debugging

The practical pedagogical value of `tf.print` lies in its ability to surface the intermediate values within the computational graph, which is otherwise opaque due to the deferred execution model in graph mode. This is important when:

- Validating Data Transformations: Ensuring preprocessing steps (such as normalization, augmentation, or reshaping) yield expected outputs.
- Debugging Shape Mismatches: Printing the shape and contents of tensors helps pinpoint errors that would otherwise result in runtime shape incompatibility exceptions.
- Exploring Model Internals: Examining activations, weights, or gradients at specific points during model training or inference.
- Tracking Variable Updates: Observing the effect of assignments or updates to variables, especially in custom training loops or complex stateful models.

Example: Debugging a Shape Mismatch

Consider a scenario where a model receives batched input data, but an inadvertent reshape operation disturbs the intended structure:

python
@tf.function
def faulty_layer(x):
    x = tf.reshape(x, [-1])
    tf.print("After reshape:", x)
    return x

input_tensor = tf.constant([[1, 2], [3, 4]])
output = faulty_layer(input_tensor)

Output:

After reshape: [1 2 3 4]

This output makes it evident that the 2D structure has been flattened, which may not be the intended behavior, thus facilitating rapid correction.

Advanced Usage: Printing During Model Training

`tf.print` can be inserted within custom training loops or callbacks to monitor loss, accuracy, or other metrics dynamically.

python
@tf.function
def train_step(inputs, labels, model, optimizer, loss_fn):
    with tf.GradientTape() as tape:
        predictions = model(inputs)
        loss = loss_fn(labels, predictions)
    grads = tape.gradient(loss, model.trainable_variables)
    optimizer.apply_gradients(zip(grads, model.trainable_variables))
    tf.print("Loss:", loss)
    return loss

This prints the loss at each training step, which is invaluable for monitoring convergence and diagnosing issues such as vanishing or exploding gradients.

`tf.print` and Graph Execution: Technical Considerations

Side-Effect Operation

`tf.print` is a side-effect operation: it does not modify tensors or alter the data flow but introduces a side-effect (printing) at a specified point in the graph. Its execution is guaranteed to occur at the point it is inserted in the graph’s dependency chain. However, if the graph executes optimizations or pruning, and the `tf.print` node is not required for the final output, it may be pruned unless explicitly attached to downstream computations.

Ensuring Execution

In cases where the graph optimizer might skip the print operation (such as when the output of `tf.print` is not otherwise used), one should ensure that the `tf.print` operation is part of the computation path. This can be done by using `tf.control_dependencies` (in TensorFlow 1.x graph mode) or by chaining the print operation appropriately.

Example for Explicit Execution in Graph Mode:
python
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

a = tf.constant([1, 2, 3])
b = tf.constant([4, 5, 6])
c = a + b
print_op = tf.print("Sum of a and b:", c)
with tf.control_dependencies([print_op]):
    d = c * 2  # Ensures tf.print runs before d is computed

with tf.Session() as sess:
    sess.run(d)

This guarantees that the print operation executes as part of the session run.

Formatting and Summarization

The `tf.print` function allows customization of its output:

- `summarize` parameter: Limits the number of elements printed for large tensors. For instance, `summarize=5` will print only the first and last five elements of each dimension, summarizing the rest.
- `output_stream` parameter: By default, output goes to the standard output, but can be redirected to standard error or a file.
- `sep` and `end` parameters: Control separator and line ending, akin to Python’s built-in `print`.

Example with a Large Tensor
python
large_tensor = tf.range(20)
tf.print("Large tensor:", large_tensor, summarize=6)

Output:

Large tensor: [0 1 2 ... 17 18 19]

This summarization improves readability when inspecting tensors with many elements.

Comparison to Python's Print and Logging

It is important to distinguish `tf.print` from Python’s built-in `print`. When using graph execution (`@tf.function` or within a computational graph), Python’s print executes at the time the function is defined, not when the computation occurs. Therefore, it does not print dynamic tensor values, but rather information about the symbolic tensors. `tf.print` evaluates at runtime and thus reflects concrete values.

Logging frameworks can also be used, but their integration with TensorFlow graphs requires additional considerations. `tf.print` remains the most direct method for runtime introspection of tensor values within TensorFlow graphs.

Practical Scenarios and Recommendations

- Debugging Data Pipelines: Place `tf.print` in functions that process batches to observe shapes, dtypes, or contents flowing into the model.
- Custom Model Layers: Insert `tf.print` in layers or custom operations to validate intermediate outputs.
- Monitoring Training: Use `tf.print` within training steps to track loss, gradients, or parameter updates.

Using `tf.print` judiciously, especially with large-scale models, is important to avoid overwhelming standard output and to focus on meaningful checkpoints in the computation.

Paragraph

The `tf.print` operation in TensorFlow outputs the actual runtime values of tensors at the point of execution within a computational graph. This makes it a critical tool for debugging, validation, and pedagogical purposes during model development and deployment. Its output reflects the genuine data flow in the graph, enabling practitioners to observe, analyze, and verify the state and transformation of tensors as computations proceed in TensorFlow's execution environment.

Other recent questions and answers regarding Printing statements in TensorFlow:

  • In real life, should we learn or implement Google Cloud tools as a machine learning engineer? What about Azure Cloud Machine Learning or AWS Cloud Machine Learning roles? Are they the same or different from each other?
  • What is the difference between Google Cloud Machine Learning and machine learning itself or a non-vendor platform?
  • What is the difference between tf.Print (capitalized) and tf.print and which function should be currently used for printing in TensorFlow?
  • How does one set limits on the amount of data being passed into tf.Print to avoid generating excessively long log files?
  • Why sessions have been removed from the TensorFlow 2.0 in favour of eager execution?
  • What is one common use case for tf.Print in TensorFlow?
  • How can multiple nodes be printed using tf.Print in TensorFlow?
  • What happens if there is a dangling print node in the graph in TensorFlow?
  • What is the purpose of assigning the output of the print call to a variable in TensorFlow?
  • How does TensorFlow's print statement differ from typical print statements in Python?

More questions and answers:

  • Field: Artificial Intelligence
  • Programme: EITC/AI/GCML Google Cloud Machine Learning (go to the certification programme)
  • Lesson: Google tools for Machine Learning (go to related lesson)
  • Topic: Printing statements in TensorFlow (go to related topic)
Tagged under: Artificial Intelligence, Computational Graph, Data Pipeline, Debugging, Deep Learning, TensorFlow
Home » Artificial Intelligence » EITC/AI/GCML Google Cloud Machine Learning » Google tools for Machine Learning » Printing statements in TensorFlow » » What could be a `tf.print` value of tensors during the execution of a computational graph?

Certification Center

USER MENU

  • My Account

CERTIFICATE CATEGORY

  • EITC Certification (117)
  • EITCA Certification (9)

What are you looking for?

  • Introduction
  • How it works?
  • EITCA Academies
  • EITCI DSJC Subsidy
  • Full EITC catalogue
  • Your order
  • Featured
  •   IT ID
  • EITCA reviews (Medium publ.)
  • About
  • Contact

EITCA Academy is a part of the European IT Certification framework

The European IT Certification framework has been established in 2008 as a Europe based and vendor independent standard in widely accessible online certification of digital skills and competencies in many areas of professional digital specializations. The EITC framework is governed by the European IT Certification Institute (EITCI), a non-profit certification authority supporting information society growth and bridging the digital skills gap in the EU.
Eligibility for EITCA Academy 90% EITCI DSJC Subsidy support
90% of EITCA Academy fees subsidized in enrolment

    EITCA Academy Secretary Office

    European IT Certification Institute ASBL
    Brussels, Belgium, European Union

    EITC / EITCA Certification Framework Operator
    Governing European IT Certification Standard
    Access contact form or call +32 25887351

    Follow EITCI on X
    Visit EITCA Academy on Facebook
    Engage with EITCA Academy on LinkedIn
    Check out EITCI and EITCA videos on YouTube

    Funded by the European Union

    Funded by the European Regional Development Fund (ERDF) and the European Social Fund (ESF) in series of projects since 2007, currently governed by the European IT Certification Institute (EITCI) since 2008

    Information Security Policy | DSRRM and GDPR Policy | Data Protection Policy | Record of Processing Activities | HSE Policy | Anti-Corruption Policy | Modern Slavery Policy
    Select LanguageAfrikaansArabicBelarusianBengaliBosnianBulgarianCatalanChinese (Simplified)Chinese (Traditional)CroatianCzechDanishDutchEnglishEstonianFilipinoFinnishFrenchGeorgianGermanGreekHebrewHindiHungarianIndonesianItalianJapaneseJavaneseKoreanKurdishLatvianLithuanianMalayMongolianMyanmar (Burmese)NepaliNorwegianPashtoPersianPolishPortuguesePunjabiRomanianRussianSerbianSlovakSlovenianSpanishSwedishTamilTeluguThaiTurkishUkrainianUrduVietnamese
    function doGLTTranslate(lang_pair) {if(lang_pair.value)lang_pair=lang_pair.value;if(lang_pair=='')return;var lang=lang_pair.split('|')[1];if(typeof _gaq!='undefined'){_gaq.push(['_trackEvent', 'GTranslate', lang, location.hostname+location.pathname+location.search]);}else {if(typeof ga!='undefined')ga('send', 'event', 'GTranslate', lang, location.hostname+location.pathname+location.search);}var plang=location.hostname.split('.')[0];if(plang.length !=2 && plang.toLowerCase() != 'zh-cn' && plang.toLowerCase() != 'zh-tw' && plang != 'hmn' && plang != 'haw' && plang != 'ceb')plang='en';location.href=location.protocol+'//'+(lang == 'en' ? '' : lang+'.')+location.hostname.replace('www.', '').replace(RegExp('^' + plang + '[.]'), '')+glt_request_uri;}

    Automatically translate to your language

    Terms and Conditions | Privacy Policy
    EITCA Academy
    • EITCA Academy on social media
    EITCA Academy


    © 2008-2026  European IT Certification Institute
    Brussels, Belgium, European Union

    TOP

    We care about your privacy

    EITCI uses cookies and similar technologies to keep this site secure, remember your choices, provide personalized experience, measure the traffic, serve more relevant content and certification programmes. You can accept all cookies or customize your preferences. Cookies are variables used to store website specific information on your device to facilitate processing of data for personalized website visit, such as login to your account, accessing the programmes, placing enrolment orders in chosen programmes and improving your EITC certification journey. You can change or withdraw your consent at any time by clicking the Consent Preferences button at the left-bottom of your screen. We respect your choices and are committed to providing you with a transparent and secure browsing experience, which may be limited when cookies aren't accepted. For more details refer to the Privacy Policy
    Customize Consent Preferences
    We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.
    The cookies categorized as Necessary are stored on your browser as they are essential for enabling the basic functionalities of the site.
    To learn more about how Google processes personal information, visit: Google privacy policy

    Necessary

    Always Active

    Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

    Functional

    Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

    Preferences

    Stores personalization choices such as interface preferences.

    External media and social features

    Allows embedded video, social, chat, and external interactive services that may set their own cookies. Keep off until the user chooses these features.

    Analytics

    Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

    Marketing and conversions

    Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

    CHAT WITH SUPPORT
    Do you have any questions?
    Attach files with the paperclip or paste screenshots into the message box (Ctrl+V). Max 5 file(s), 10 MB each.
    We will reply here and by email. Your conversation is tracked with a support token.