- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
PyTorch Tutorial
- PyTorch Tutorial
- PyTorch Introduction
- PyTorch Installation
- PyTorch Basics
- PyTorch Tensors
- PyTorch Neural Network Basics
- PyTorch First Neural Network
- PyTorch Data Processing and Loading
- PyTorch Linear Regression
- PyTorch Convolutional Neural Network
- PyTorch Recurrent Neural Network
- PyTorch Datasets
- PyTorch Data Transforms
- Pytorch torch
- PyTorch torch.nn
- Transformer Model
- PyTorch Transformer
- PyTorch torch.optim
- PyTorch torchvision
- PyTorch Model Deployment
- PyTorch Model Save and Load
- PyTorch Image Classification
- PyTorch Text Sentiment Analysis
- PyTorch Autograd
- PyTorch GPU / CUDA Acceleration
- PyTorch Loss Functions
- PyTorch Learning Rate Scheduler
- PyTorch Transfer Learning
- PyTorch Batch Normalization
- PyTorch LSTM / GRU
- PyTorch Word Embedding
- PyTorch Generative Adversarial Network
- PyTorch Autoencoder
- PyTorch Model Evaluation and Debugging
- PyTorch torchtext
- PyTorch Mixed Precision Training
- PyTorch TorchScript/ONNX Export
- PyTorch Distributed Training
- PyTorch Attention Mechanism
PyTorch torch.seed Function
The torch.seed() function sets the random seed for generating random numbers in PyTorch. This function is used to ensure reproducibility of results when running code that involves random operations, such as weight initialization or data shuffling.
Syntax:
torch.seed()
Parameters:
- None
Returns:
- A 64-bit unsigned integer representing the newly generated random seed.
Example:
import torch
# Set the random seed
torch.seed()
# Now random operations will be based on the new seed
x = torch.rand(3, 3)
print(x)
Note:
- Calling
torch.seed()automatically seeds all random number generators used by PyTorch, including those for CPU and CUDA (if available). - This function does not accept any arguments. It generates a random seed from the system's entropy source.
- If you need to set a specific seed value, use
torch.manual_seed(seed)instead.
Related Functions:
torch.manual_seed()β Set a specific seed value.torch.cuda.manual_seed()β Set the seed for CUDA random number generation.torch.cuda.manual_seed_all()β Set the seed for all CUDA devices.
YouTip