tenstorrent / tt-buda

Tenstorrent TT-BUDA Repository
Other
162 stars 21 forks source link

issues while running tt-buda-demos #17

Closed jes-rey closed 2 months ago

jes-rey commented 3 months ago

ERROR | pybuda.run.impl:startdeviceprocesses:1180 - Process spawn error: An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if _name == '__main':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

smoke.py runs fine but when I try to run bert or resnet it blows up on the same issue, thanks

milank94 commented 3 months ago

@jes-rey can you provide some additional details to help debug:

refill commented 3 months ago

check your python environment.

milank94 commented 3 months ago

No response for follow-up.

@jes-rey please re-open if issue is still persistent.

breuera commented 2 months ago

I am having the same problems as the author of the issue.

Which device you are on

e75

Which version of pybuda

I tried v0.10.9.gs.240401-alpha, v0.11.0.gs.240415-alpha natively (Ubuntu 22.04.4 LTS (GNU/Linux 6.8.7+ x86_64)) and ghcr.io/tenstorrent/tt-buda/ubuntu-22-04-amd64/gs, ghcr.io/tenstorrent/tt-buda/ubuntu-20-04-amd64/gs using Docker. All show the same error.

Which version of driver (tt-kmd) and firmware (tt-firmware)

FW Version: 1.7.0.0 tt-kmd: 1.27

Which command / script you are trying to execute

python resnet.py and python bert.py with the scripts taken from the tutorials and attached. I am also attaching the entire output of the resnet script (resnet.log).

I have added .txt to match GitHub's requirements: bert.py.txt resnet.py.txt resnet.log

milank94 commented 2 months ago

Thanks @breuera. I've root caused this issue and opened a FAQ item in our Discord channel: https://discord.com/channels/863154240319258674/1231945279864045680

Working on updating the FAQ in the repo as well: https://github.com/tenstorrent/tt-buda-demos/blob/main/FAQ.md

Can you give the following solution a try?

Solution:

If trying to run pybuda application from a Python file (.py), make sure that the main module can be safely imported by a new Python interpreter without causing unintended side effects (such a starting a new process).

One should protect the “entry point” of the program by using if __name__ == '__main__': as follows:

# test_bert.py

import pybuda
from transformers import BertForMaskedLM, BertTokenizer

if __name__ == '__main__':

    # Load Bert tokenizer and model from HuggingFace
    model_ckpt = "bert-base-uncased"
    tokenizer = BertTokenizer.from_pretrained(model_ckpt)
    model = BertForMaskedLM.from_pretrained(model_ckpt)

    compiler_cfg = pybuda.config._get_global_compiler_config()  # load global compiler config object
    compiler_cfg.default_df_override = pybuda._C.DataFormat.Float16_b

    # Load data sample
    sample_text = "The capital of France is [MASK]."

    # Data preprocessing
    input_tokens = tokenizer(
        sample_text,
        max_length=128,
        padding="max_length",
        truncation=True,
        return_tensors="pt",
    )

    # Run inference on Tenstorrent device
    output_q = pybuda.run_inference(
        pybuda.PyTorchModule("pt_bert_masked_lm", model),
        inputs=[input_tokens],
    )
    output = output_q.get()

    # Data postprocessing
    mask_token_index = (input_tokens["input_ids"] == tokenizer.mask_token_id)[0].nonzero(as_tuple=True)[0]
    predicted_token_id = output[0].value()[0, mask_token_index].argmax(axis=-1)
    answer = tokenizer.decode(predicted_token_id)

    # Answer - "paris"
    print(f"Context: {sample_text}")
    print(f"Answer: {answer}")
breuera commented 2 months ago

Thank you @milank94. I added the if __name__ == '__main__': to both scripts and the compiler now runs in my installations.