Skip to content

Commit 7d69b26

Browse files
authored
update marker of examples.md (#1458)
1 parent 6567c7a commit 7d69b26

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

docs/tutorials/examples.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ output = model(data)
3535

3636
#### Complete - Float32
3737

38-
[//]: # (train_single_fp32_complete)
38+
[//]: # (marker_train_single_fp32_complete)
3939
```
4040
import torch
4141
import torchvision
@@ -79,11 +79,11 @@ torch.save({
7979
'optimizer_state_dict': optimizer.state_dict(),
8080
}, 'checkpoint.pth')
8181
```
82-
[//]: # (train_single_fp32_complete)
82+
[//]: # (marker_train_single_fp32_complete)
8383

8484
#### Complete - BFloat16
8585

86-
[//]: # (train_single_bf16_complete)
86+
[//]: # (marker_train_single_bf16_complete)
8787
```
8888
import torch
8989
import torchvision
@@ -128,15 +128,15 @@ torch.save({
128128
'optimizer_state_dict': optimizer.state_dict(),
129129
}, 'checkpoint.pth')
130130
```
131-
[//]: # (train_single_bf16_complete)
131+
[//]: # (marker_train_single_bf16_complete)
132132

133133
### Distributed Training
134134

135135
Distributed training with PyTorch DDP is accelerated by oneAPI Collective Communications Library Bindings for Pytorch\* (oneCCL Bindings for Pytorch\*). The extension supports FP32 and BF16 data types. More detailed information and examples are available at its [Github repo](https://github.com/intel/torch-ccl).
136136

137137
**Note:** When performing distributed training with BF16 data type, use oneCCL Bindings for Pytorch\*. Due to a PyTorch limitation, distributed training with BF16 data type with Intel® Extension for PyTorch\* is not supported.
138138

139-
[//]: # (train_ddp_complete)
139+
[//]: # (marker_train_ddp_complete)
140140
```
141141
import os
142142
import torch
@@ -194,7 +194,7 @@ torch.save({
194194
'optimizer_state_dict': optimizer.state_dict(),
195195
}, 'checkpoint.pth')
196196
```
197-
[//]: # (train_ddp_complete)
197+
[//]: # (marker_train_ddp_complete)
198198

199199
## Inference
200200

@@ -206,7 +206,7 @@ The `optimize` function of Intel® Extension for PyTorch\* applies optimizations
206206

207207
##### Resnet50
208208

209-
[//]: # (inf_rn50_imp_fp32)
209+
[//]: # (marker_inf_rn50_imp_fp32)
210210
```
211211
import torch
212212
import torchvision.models as models
@@ -223,11 +223,11 @@ model = ipex.optimize(model)
223223
with torch.no_grad():
224224
model(data)
225225
```
226-
[//]: # (inf_rn50_imp_fp32)
226+
[//]: # (marker_inf_rn50_imp_fp32)
227227

228228
##### BERT
229229

230-
[//]: # (inf_bert_imp_fp32)
230+
[//]: # (marker_inf_bert_imp_fp32)
231231
```
232232
import torch
233233
from transformers import BertModel
@@ -248,15 +248,15 @@ model = ipex.optimize(model)
248248
with torch.no_grad():
249249
model(data)
250250
```
251-
[//]: # (inf_bert_imp_fp32)
251+
[//]: # (marker_inf_bert_imp_fp32)
252252

253253
#### TorchScript Mode
254254

255255
We recommend you take advantage of Intel® Extension for PyTorch\* with [TorchScript](https://pytorch.org/docs/stable/jit.html) for further optimizations.
256256

257257
##### Resnet50
258258

259-
[//]: # (inf_rn50_ts_fp32)
259+
[//]: # (marker_inf_rn50_ts_fp32)
260260
```
261261
import torch
262262
import torchvision.models as models
@@ -277,11 +277,11 @@ with torch.no_grad():
277277
278278
model(data)
279279
```
280-
[//]: # (inf_rn50_ts_fp32)
280+
[//]: # (marker_inf_rn50_ts_fp32)
281281

282282
##### BERT
283283

284-
[//]: # (inf_bert_ts_fp32)
284+
[//]: # (marker_inf_bert_ts_fp32)
285285
```
286286
import torch
287287
from transformers import BertModel
@@ -306,13 +306,13 @@ with torch.no_grad():
306306
307307
model(data)
308308
```
309-
[//]: # (inf_bert_ts_fp32)
309+
[//]: # (marker_inf_bert_ts_fp32)
310310

311311
#### TorchDynamo Mode (Experimental, _NEW feature from 2.0.0_)
312312

313313
##### Resnet50
314314

315-
[//]: # (inf_rn50_dynamo_fp32)
315+
[//]: # (marker_inf_rn50_dynamo_fp32)
316316
```
317317
import torch
318318
import torchvision.models as models
@@ -330,11 +330,11 @@ model = torch.compile(model, backend="ipex")
330330
with torch.no_grad():
331331
model(data)
332332
```
333-
[//]: # (inf_rn50_dynamo_fp32)
333+
[//]: # (marker_inf_rn50_dynamo_fp32)
334334

335335
##### BERT
336336

337-
[//]: # (inf_bert_dynamo_fp32)
337+
[//]: # (marker_inf_bert_dynamo_fp32)
338338
```
339339
import torch
340340
from transformers import BertModel
@@ -356,7 +356,7 @@ model = torch.compile(model, backend="ipex")
356356
with torch.no_grad():
357357
model(data)
358358
```
359-
[//]: # (inf_bert_dynamo_fp32)
359+
[//]: # (marker_inf_bert_dynamo_fp32)
360360

361361
### BFloat16
362362

@@ -367,7 +367,7 @@ We recommend using Auto Mixed Precision (AMP) with BFloat16 data type.
367367

368368
##### Resnet50
369369

370-
[//]: # (inf_rn50_imp_bf16)
370+
[//]: # (marker_inf_rn50_imp_bf16)
371371
```
372372
import torch
373373
import torchvision.models as models
@@ -385,11 +385,11 @@ with torch.no_grad():
385385
with torch.cpu.amp.autocast():
386386
model(data)
387387
```
388-
[//]: # (inf_rn50_imp_bf16)
388+
[//]: # (marker_inf_rn50_imp_bf16)
389389

390390
##### BERT
391391

392-
[//]: # (inf_bert_imp_bf16)
392+
[//]: # (marker_inf_bert_imp_bf16)
393393
```
394394
import torch
395395
from transformers import BertModel
@@ -411,15 +411,15 @@ with torch.no_grad():
411411
with torch.cpu.amp.autocast():
412412
model(data)
413413
```
414-
[//]: # (inf_bert_imp_bf16)
414+
[//]: # (marker_inf_bert_imp_bf16)
415415

416416
#### TorchScript Mode
417417

418418
We recommend you take advantage of Intel® Extension for PyTorch\* with [TorchScript](https://pytorch.org/docs/stable/jit.html) for further optimizations.
419419

420420
##### Resnet50
421421

422-
[//]: # (inf_rn50_ts_bf16)
422+
[//]: # (marker_inf_rn50_ts_bf16)
423423
```
424424
import torch
425425
import torchvision.models as models
@@ -440,11 +440,11 @@ with torch.no_grad():
440440
441441
model(data)
442442
```
443-
[//]: # (inf_rn50_ts_bf16)
443+
[//]: # (marker_inf_rn50_ts_bf16)
444444

445445
##### BERT
446446

447-
[//]: # (inf_bert_ts_f16)
447+
[//]: # (marker_inf_bert_ts_f16)
448448
```
449449
import torch
450450
from transformers import BertModel
@@ -470,7 +470,7 @@ with torch.no_grad():
470470
471471
model(data)
472472
```
473-
[//]: # (inf_bert_ts_f16)
473+
[//]: # (marker_inf_bert_ts_f16)
474474

475475
### INT8
476476

@@ -491,7 +491,7 @@ Please follow the steps below to perform static calibration:
491491
7. Save the INT8 model into a `pt` file.
492492

493493

494-
[//]: # (int8_static)
494+
[//]: # (marker_int8_static)
495495
```
496496
import os
497497
import torch
@@ -521,7 +521,7 @@ with torch.no_grad():
521521
522522
traced_model.save("quantized_model.pt")
523523
```
524-
[//]: # (int8_static)
524+
[//]: # (marker_int8_static)
525525

526526
##### Dynamic Quantization
527527

@@ -535,7 +535,7 @@ Please follow the steps below to perform static calibration:
535535
6. Run inference to perform dynamic quantization.
536536
7. Save the INT8 model into a `pt` file.
537537

538-
[//]: # (int8_dynamic)
538+
[//]: # (marker_int8_dynamic)
539539
```
540540
import os
541541
import torch
@@ -563,7 +563,7 @@ with torch.no_grad():
563563
564564
traced_model.save("quantized_model.pt")
565565
```
566-
[//]: # (int8_dynamic)
566+
[//]: # (marker_int8_dynamic)
567567

568568
#### Deployment
569569

@@ -575,7 +575,7 @@ Follow the steps below:
575575
2. Load the INT8 model from the saved file.
576576
3. Run inference.
577577

578-
[//]: # (int8_deploy)
578+
[//]: # (marker_int8_deploy)
579579
```
580580
import torch
581581
#################### code changes ####################
@@ -590,7 +590,7 @@ data = torch.rand(<shape>)
590590
with torch.no_grad():
591591
model(data)
592592
```
593-
[//]: # (int8_deploy)
593+
[//]: # (marker_int8_deploy)
594594

595595
oneDNN provides [oneDNN Graph Compiler](https://github.com/oneapi-src/oneDNN/tree/dev-graph-preview4/doc#onednn-graph-compiler) as a prototype feature that could boost performance for selective topologies. No code change is required. Install <a class="reference external" href="installation.md#installation_onednn_graph_compiler">a binary</a> with this feature enabled. We verified this feature with `Bert-large`, `bert-base-cased`, `roberta-base`, `xlm-roberta-base`, `google-electra-base-generator` and `google-electra-base-discriminator`.
596596

@@ -604,7 +604,7 @@ The example code below works for all data types.
604604

605605
**example-app.cpp**
606606

607-
[//]: # (cppsdk_sample)
607+
[//]: # (marker_cppsdk_sample)
608608
```cpp
609609
#include <torch/script.h>
610610
#include <iostream>
@@ -626,11 +626,11 @@ int main(int argc, const char* argv[]) {
626626
return 0;
627627
}
628628
```
629-
[//]: # (cppsdk_sample)
629+
[//]: # (marker_cppsdk_sample)
630630
631631
**CMakeLists.txt**
632632
633-
[//]: # (cppsdk_cmake)
633+
[//]: # (marker_cppsdk_cmake)
634634
```cmake
635635
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
636636
project(example-app)
@@ -642,7 +642,7 @@ target_link_libraries(example-app "${TORCH_LIBRARIES}")
642642
643643
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)
644644
```
645-
[//]: # (cppsdk_cmake)
645+
[//]: # (marker_cppsdk_cmake)
646646

647647
**Command for compilation**
648648

0 commit comments

Comments
 (0)