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

model--BART--Shubham09 NAN output #400

Open
AmosLewis opened this issue Nov 26, 2024 · 0 comments
Open

model--BART--Shubham09 NAN output #400

AmosLewis opened this issue Nov 26, 2024 · 0 comments

Comments

@AmosLewis
Copy link
Collaborator

We have to revisit it later when we have time.

In the nlp.py, when you change the input to exact the same as huggingface model.

            if self.name == "model--BART--Shubham09":
                tensors[0] = numpy.array([[    0, 40710,  3923, 12346,    16,  2351,    10,  3944,    14, 26232, 7396,  4687,     4,     2]])
                tensors[1] = numpy.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
                tensors[2] = numpy.array([[    2,     0, 40710,  3923, 12346]])
                print("Change input of model--BART--Shubham09")

The output NAN for both golden and iree.

matching values with (rtol,atol) = [0.001, 0.001]: 0 of 251325 = 0.0%
Test Result:
TestResult(name='model--BART--Shubham09', input=TestTensors(<class 'numpy.ndarray'>): (array([[    0, 40710,  3923, 12346,    16,  2351,    10,  3944,    14,
        26232,  7396,  4687,     4,     2]]), array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]), array([[    2,     0, 40710,  3923, 12346]])), gold_output=TestTensors(<class 'numpy.ndarray'>): [array([[[nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan]]], dtype=float32)], output=TestTensors(<class 'numpy.ndarray'>): (array([[[nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan],
        [nan, nan, nan, ..., nan, nan, nan]]], dtype=float32),))

The way to get the huggingface model input.

from transformers import BartTokenizer, BartForConditionalGeneration

# Initialize tokenizer and model
tokenizer = BartTokenizer.from_pretrained('Shubham09/BART')
model = BartForConditionalGeneration.from_pretrained('Shubham09/BART')

# Example input and decoder sequences
input_text = "Hugging Face is creating a tool that democratizes AI."
decoder_text = "</s><s>Hugging Face"

# Tokenize inputs
inputs = tokenizer(input_text, return_tensors='pt')
decoder_inputs = tokenizer(decoder_text, return_tensors='pt', add_special_tokens=False)
print("decoder_input_ids: ")
print(decoder_inputs['input_ids'])

# Generate output
outputs = model.generate(
    input_ids=inputs['input_ids'],
    attention_mask=inputs['attention_mask'],
    decoder_input_ids=decoder_inputs['input_ids']
)

print("input_ids: ")
print(inputs['input_ids']) # numpy.array([[    0, 40710,  3923, 12346,    16,  2351,    10,  3944,    14, 26232, 7396,  4687,     4,     2]])
print("attention_mask: ")
print(inputs['attention_mask']) # array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
print("decoder_input_ids: ")
print(decoder_inputs['input_ids']) # array([[    2,     0, 40710,  3923, 12346]])

# Decode the output
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(decoded_output)
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

1 participant