Skip to content

PT Lab 1 section 1.3 error in testing the Sequential API code #191

@DaveSprague

Description

@DaveSprague

The current version of the code gets a name error. Here's the code:

# Test the model with example input
x_input = torch.tensor([[1, 2.]])
model_output = model(x_input)
print(f"input shape: {x_input.shape}")
print(f"output shape: {y.shape}")
print(f"output result: {y}")

and the resulting error:

NameError                                 Traceback (most recent call last)
[<ipython-input-15-d4b3446276a7>](https://localhost:8080/#) in <cell line: 0>()
      3 model_output = model(x_input)
      4 print(f"input shape: {x_input.shape}")
----> 5 print(f"output shape: {y.shape}")
      6 print(f"output result: {y}")

NameError: name 'y' is not defined

The code should be corrected as follows:

# Test the model with example input
x_input = torch.tensor([[1, 2.]])
y = model(x_input)
print(f"input shape: {x_input.shape}")
print(f"output shape: {y.shape}")
print(f"output result: {y}")

Cause: Two different variable names are used for the output of the model. On the third line model_output is used but in two later lines y is used. The corrected code above uses a consistent variable name of y.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions