Skip to content

Commit

Permalink
#13396: Add data parallel support for distilbert model
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudharsan-V committed Oct 18, 2024
1 parent e902289 commit af74509
Show file tree
Hide file tree
Showing 10 changed files with 1,453 additions and 0 deletions.
36 changes: 36 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,42 @@ def device(request, device_params):
ttnn.close_device(device)


@pytest.fixture(scope="function")
def multi_device(request, device_params):
import ttnn

if ttnn.get_num_devices() < 2:
device_id = request.config.getoption("device_id")
request.node.pci_ids = [ttnn.GetPCIeDeviceID(device_id)]

num_devices = ttnn.GetNumPCIeDevices()
assert device_id < num_devices, "CreateDevice not supported for non-mmio device"
device = ttnn.CreateDevice(device_id=device_id, dispatch_core_type=get_dispatch_core_type(), **device_params)
ttnn.SetDefaultDevice(device)

yield device

ttnn.DumpDeviceProfiler(device)

ttnn.synchronize_device(device)
ttnn.close_device(device)
else:
mesh_device = ttnn.open_mesh_device(
ttnn.MeshShape(1, 2),
dispatch_core_type=get_dispatch_core_type(),
**device_params,
)

logger.debug(f"multidevice with {mesh_device.get_num_devices()} devices is created")
yield mesh_device

for device in mesh_device.get_devices():
ttnn.DumpDeviceProfiler(device)

ttnn.close_mesh_device(mesh_device)
del mesh_device


@pytest.fixture(scope="function")
def pcie_devices(request, device_params):
import ttnn
Expand Down
35 changes: 35 additions & 0 deletions models/demos/wormhole/distilbert/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Distilbert Model

# Platforms:
WH N300, N150

## Introduction
DistilBERT is a transformers model, smaller and faster than BERT, which was pretrained on the same corpus in a self-supervised fashion, using the BERT base model as a teacher. The DistilBERT Question Answering model is fine-tuned specifically for the task of extracting answers from a given context, making it highly efficient for question-answering applications.

# Details
The entry point to distilebert model is distilbert_for_question_answering in `models/demos/wormhole/distilbert/tt/ttnn_optimized_distilbert.py`. The model picks up certain configs and weights from huggingface pretrained model. We have used `distilbert-base-uncased-distilled-squad` version from huggingface as our reference.

This model, located in `models/demos/wormhole`, supports functionality on both N150 and N300 devices, depending on availability. If the device is N300, the weights and inputs are distributed across the device, allowing the model to run in parallel.

## Sequence Size: 384

Sequence size determines the maximum length of input sequences processed by the model, optimizing performance and compatibility. It's recommended to set the `sequence_size` to 384

## Batch size: 8

Batch Size determines the number of input sequences processed simultaneously during training or inference, impacting computational efficiency and memory usage. It's recommended to set the `batch_size` to 8

Use `pytest --disable-warnings models/demos/wormhole/distilbert/demo/demo.py::test_demo[wormhole_b0-True-models.demos.wormhole.distilbert.tt.ttnn_optimized_distilbert-distilbert-base-uncased-distilled-squad-models/demos/distilbert/demo/input_data.json]` to run the ttnn_optimized_distilbert demo.


If you wish to run the demo with a different input, change the pytest fixture input_loc to the desired location and use `pytest --disable-warnings models/demos/wormhole/distilbert/demo/demo.py::test_demo[wormhole_b0-True-models.demos.wormhole.distilbert.tt.ttnn_optimized_distilbert-distilbert-base-uncased-distilled-squad-models/demos/distilbert/demo/input_data.json]`. This file is expected to have exactly 8 inputs.

Our second demo is designed to run SQuADV2 dataset, run this with `pytest --disable-warnings models/demos/wormhole/distilbert/demo/demo.py::test_demo_squadv2[wormhole_b0-True-3-models.demos.wormhole.distilbert.tt.ttnn_optimized_distilbert-distilbert-base-uncased-distilled-squad]`.

If you wish to run for `n_iterations` samples, use `pytest --disable-warnings models/demos/wormhole/distilbert/demo/demo.py::test_demo_squadv2[wormhole_b0-True-<n_iterations>-models.demos.wormhole.distilbert.tt.ttnn_optimized_distilbert-distilbert-base-uncased-distilled-squad]`

## Inputs

The demo receives inputs from respective input_data.json by default. To modify the inputs or specify a different path, adjust the input_path parameter in the command accordingly. It's recommended to avoid direct modifications to the input_data.json file.

# Owner Sudharsan Vijayaraghavan
Loading

0 comments on commit af74509

Please sign in to comment.