{"id":47574,"date":"2026-11-23T22:06:09","date_gmt":"2026-11-23T22:06:09","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=47574"},"modified":"2026-11-23T22:06:09","modified_gmt":"2026-11-23T22:06:09","slug":"pytorch-lab-7-pytorch-cuda-semantics","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/pytorch-lab-7-pytorch-cuda-semantics\/","title":{"rendered":"PyTorch Lab &#8211; 7 &#8211; Pytorch CUDA Semantics"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This page covers a PyTorch lab notebook that fits a linear regression model with autograd and manual gradient descent. The title mentions CUDA, but the notebook above never uses a GPU, so the sections below explain what the code does and fix its problems. They also show how to run the same model on a GPU using PyTorch&#039;s CUDA rules: choosing a device, keeping tensors on the same device, asynchronous execution and GPU memory.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/25455e469b4a71679612e6a85d850ad2.js\"><\/script>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What the notebook above actually does<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The embedded notebook builds a 15-point dataset with NumPy and turns it into tensors with <code>torch.from_numpy<\/code>. It then trains the model <code>y = x \u00b7 w1 \u00b7 w2<\/code> with two weight tensors that have <code>requires_grad=True<\/code>. Each pass through the training loop does four things:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Forward pass:<\/strong> <code>X_train.mm(w1).mm(w2)<\/code> computes predictions with matrix multiplication. There is no activation function, so the model is linear.<\/li>\n\n\n<li><strong>Loss:<\/strong> <code>(y_pred - Y_train).pow(2).sum()<\/code> is the sum of squared errors. It equals <code>nn.MSELoss(reduction=&#039;sum&#039;)<\/code>, not the default <code>nn.MSELoss()<\/code>, which takes the mean.<\/li>\n\n\n<li><strong>Backward pass:<\/strong> <code>loss.backward()<\/code> fills <code>w1.grad<\/code> and <code>w2.grad<\/code>.<\/li>\n\n\n<li><strong>Update:<\/strong> inside <code>torch.no_grad()<\/code>, each weight moves against its gradient, and the gradients are then reset with <code>.grad.zero_()<\/code>. This reset is needed because PyTorch adds new gradients to the old ones instead of replacing them.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Every tensor in the notebook is created on the CPU, and nothing is moved to a GPU. To show CUDA behaviour, the code has to choose a device and put the data and the parameters on it. The corrected version below does this.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Problems in the original notebook<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The loop runs 9 times, not 10.<\/strong> <code>range(1, 10)<\/code> stops before 10. The comment says &quot;Start at 10&quot;.<\/li>\n\n\n<li><strong>No progress is ever printed.<\/strong> <code>if iter % 50 == 0<\/code> is never true when the loop runs fewer than 50 times.<\/li>\n\n\n<li><strong>The model barely trains.<\/strong> With a learning rate of <code>1e-6<\/code> and 9 iterations, the weights hardly move from their random starting values. The predictions shown (about 0.26 to 1.24) are far from the targets (about 1.6 to 3.5). The note &quot;Our training has produced a rather accurate regression line&quot; is wrong.<\/li>\n\n\n<li><strong>There is no bias term.<\/strong> <code>x \u00b7 w1 \u00b7 w2<\/code> is the same as <code>x \u00b7 w<\/code>, a line forced through the origin. This data needs an intercept. Stacking two 1\u00d71 weights with no activation in between adds nothing over a single weight.<\/li>\n\n\n<li><strong><code>iter<\/code> is used as a variable name.<\/strong> This hides Python&#039;s built-in <code>iter()<\/code> function.<\/li>\n\n\n<li><strong>The final prediction builds a gradient graph it doesn&#039;t need.<\/strong> The output shows <code>grad_fn=&lt;MmBackward&gt;<\/code>. Run inference inside <code>torch.no_grad()<\/code>. Newer PyTorch versions print the name as <code>MmBackward0<\/code>.<\/li>\n\n\n<li><strong>Typos in the markdown cells:<\/strong> &quot;defualt&quot; should be &quot;default&quot; and &quot;Foward&quot; should be &quot;Forward&quot;.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Corrected lab that runs on CPU or GPU<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This version keeps the manual-autograd approach of the original. It adds a bias, uses mean squared error, uses a learning rate that actually trains the model, and runs on CUDA when a GPU is available.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">import numpy <span class=\"hljs-keyword\">as<\/span> np\nimport torch\nimport matplotlib.pyplot <span class=\"hljs-keyword\">as<\/span> plt\n\n<span class=\"hljs-comment\"># 1. Pick a device once and use it everywhere<\/span>\ndevice = torch.device(<span class=\"hljs-string\">\"cuda\"<\/span> <span class=\"hljs-keyword\">if<\/span> torch.cuda.is_available() <span class=\"hljs-keyword\">else<\/span> <span class=\"hljs-string\">\"cpu\"<\/span>)\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Using device:\"<\/span>, device)\n\nx_train = np.<span class=\"hljs-keyword\">array<\/span>(&#91;&#91;<span class=\"hljs-number\">4.7<\/span>], &#91;<span class=\"hljs-number\">2.4<\/span>], &#91;<span class=\"hljs-number\">7.5<\/span>], &#91;<span class=\"hljs-number\">7.1<\/span>], &#91;<span class=\"hljs-number\">4.3<\/span>], &#91;<span class=\"hljs-number\">7.816<\/span>], &#91;<span class=\"hljs-number\">8.9<\/span>], &#91;<span class=\"hljs-number\">5.2<\/span>],\n                    &#91;<span class=\"hljs-number\">8.59<\/span>], &#91;<span class=\"hljs-number\">2.1<\/span>], &#91;<span class=\"hljs-number\">8<\/span>], &#91;<span class=\"hljs-number\">10<\/span>], &#91;<span class=\"hljs-number\">4.5<\/span>], &#91;<span class=\"hljs-number\">6<\/span>], &#91;<span class=\"hljs-number\">4<\/span>]], dtype=np.float32)\ny_train = np.<span class=\"hljs-keyword\">array<\/span>(&#91;&#91;<span class=\"hljs-number\">2.6<\/span>], &#91;<span class=\"hljs-number\">1.6<\/span>], &#91;<span class=\"hljs-number\">3.09<\/span>], &#91;<span class=\"hljs-number\">2.4<\/span>], &#91;<span class=\"hljs-number\">2.4<\/span>], &#91;<span class=\"hljs-number\">3.357<\/span>], &#91;<span class=\"hljs-number\">2.6<\/span>], &#91;<span class=\"hljs-number\">1.96<\/span>],\n                    &#91;<span class=\"hljs-number\">3.53<\/span>], &#91;<span class=\"hljs-number\">1.76<\/span>], &#91;<span class=\"hljs-number\">3.2<\/span>], &#91;<span class=\"hljs-number\">3.5<\/span>], &#91;<span class=\"hljs-number\">1.6<\/span>], &#91;<span class=\"hljs-number\">2.5<\/span>], &#91;<span class=\"hljs-number\">2.2<\/span>]], dtype=np.float32)\n\n<span class=\"hljs-comment\"># 2. Copy the data to the device (from_numpy is CPU-only; .to() copies to the GPU)<\/span>\nX = torch.from_numpy(x_train).to(device)\nY = torch.from_numpy(y_train).to(device)\n\n<span class=\"hljs-comment\"># 3. Create parameters directly on the device so they stay leaf tensors<\/span>\ntorch.manual_seed(<span class=\"hljs-number\">0<\/span>)\nw = torch.rand(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>, device=device, requires_grad=<span class=\"hljs-keyword\">True<\/span>)\nb = torch.zeros(<span class=\"hljs-number\">1<\/span>, device=device, requires_grad=<span class=\"hljs-keyword\">True<\/span>)\n\nlearning_rate = <span class=\"hljs-number\">1e-2<\/span>\n\n<span class=\"hljs-keyword\">for<\/span> step in range(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">3001<\/span>):\n    y_pred = X.mm(w) + b\n    loss = (y_pred - Y).pow(<span class=\"hljs-number\">2<\/span>).mean()\n\n    loss.backward()\n\n    with torch.no_grad():\n        w -= learning_rate * w.grad\n        b -= learning_rate * b.grad\n        w.grad.zero_()\n        b.grad.zero_()\n\n    <span class=\"hljs-keyword\">if<\/span> step % <span class=\"hljs-number\">500<\/span> == <span class=\"hljs-number\">0<\/span>:\n        <span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">\"step {step:5d}  loss {loss.item():.4f}\"<\/span>)\n\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"w:\"<\/span>, w.item(), <span class=\"hljs-string\">\"b:\"<\/span>, b.item())\n\n<span class=\"hljs-comment\"># 4. Inference without building a graph, then move back to CPU for NumPy<\/span>\nwith torch.no_grad():\n    predicted = (X.mm(w) + b).cpu().numpy()\n\norder = np.argsort(x_train&#91;:, <span class=\"hljs-number\">0<\/span>])\nplt.figure(figsize=(<span class=\"hljs-number\">12<\/span>, <span class=\"hljs-number\">8<\/span>))\nplt.scatter(x_train, y_train, label=<span class=\"hljs-string\">\"Original data\"<\/span>, s=<span class=\"hljs-number\">250<\/span>, c=<span class=\"hljs-string\">\"g\"<\/span>)\nplt.plot(x_train&#91;order], predicted&#91;order], label=<span class=\"hljs-string\">\"Fitted line\"<\/span>)\nplt.legend()\nplt.show()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The loss should fall quickly at first and then level off by the later printouts. The fitted line should pass through the middle of the points, not sit below all of them. A learning rate of <code>1e-2<\/code> works because the loss is a mean over this data. Much larger values (above roughly <code>0.02<\/code> here) make the training diverge.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CUDA semantics you need to know<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Device selection.<\/strong> <code>torch.device(&quot;cuda&quot;)<\/code> means the current GPU, which is normally <code>cuda:0<\/code>. Use <code>cuda:1<\/code> and so on to target a specific card. To limit which GPUs a process can see, set <code>CUDA_VISIBLE_DEVICES<\/code> before Python starts. The visible GPUs are renumbered from <code>cuda:0<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">python -c <span class=\"hljs-string\">\"import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available(), torch.cuda.device_count())\"<\/span>\nCUDA_VISIBLE_DEVICES=<span class=\"hljs-number\">1<\/span> python train.py   <span class=\"hljs-comment\"># physical GPU 1 appears as cuda:0<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">If <code>torch.version.cuda<\/code> prints <code>None<\/code>, the installed PyTorch is a CPU-only build. In that case, install a CUDA-enabled build from the selector on pytorch.org.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>All tensors in one operation must be on the same device.<\/strong> PyTorch never moves data between devices on its own. Multiplying a <code>cuda:0<\/code> tensor by a CPU tensor raises an error. The result of an operation stays on the device of its inputs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><code>.to(device)<\/code> on a parameter creates a new, non-leaf tensor.<\/strong> This is the most common autograd mistake with GPUs:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">w = torch.rand(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>, requires_grad=<span class=\"hljs-keyword\">True<\/span>).to(<span class=\"hljs-string\">\"cuda\"<\/span>)\n<span class=\"hljs-keyword\">print<\/span>(w.is_leaf)   <span class=\"hljs-comment\"># False -&gt; w.grad stays None after backward()<\/span>\n\n<span class=\"hljs-comment\"># Correct options<\/span>\nw = torch.rand(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>, device=<span class=\"hljs-string\">\"cuda\"<\/span>, requires_grad=<span class=\"hljs-keyword\">True<\/span>)\nw = torch.rand(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">1<\/span>).to(<span class=\"hljs-string\">\"cuda\"<\/span>).requires_grad_()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">When you use <code>nn.Module<\/code>, call <code>model.to(device)<\/code>. This moves the parameters in place, so the problem does not occur.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Execution is asynchronous.<\/strong> CUDA kernels are queued, and Python continues before they finish. Some operations make the CPU wait for the GPU to catch up: <code>.item()<\/code>, <code>.cpu()<\/code>, <code>.numpy()<\/code> after <code>.cpu()<\/code>, and printing a tensor. Calling <code>loss.item()<\/code> on every step slows training for this reason, which is why the corrected loop only logs every 500 steps. For accurate timing, call <code>torch.cuda.synchronize()<\/code> before reading the clock:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> time\ntorch.cuda.synchronize()\nstart = time.perf_counter()\nout = X.mm(w)\ntorch.cuda.synchronize()\nprint(<span class=\"hljs-string\">\"elapsed:\"<\/span>, time.perf_counter() - start)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Memory is cached.<\/strong> PyTorch keeps freed GPU memory in a cache so it can reuse it quickly. Because of this, <code>nvidia-smi<\/code> shows more memory in use than <code>torch.cuda.memory_allocated()<\/code> reports. <code>torch.cuda.memory_reserved()<\/code> shows the cached total. <code>torch.cuda.empty_cache()<\/code> returns unused cached blocks to the driver, but it cannot free tensors that your code still references.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Faster host-to-device copies.<\/strong> For large batches, page-locked memory lets copies overlap with GPU work:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">batch = batch.pin_memory().to(device, non_blocking=<span class=\"hljs-keyword\">True<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">With a <code>DataLoader<\/code>, passing <code>pin_memory=True<\/code> does the pinning step for you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common errors and fixes<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Error message<\/th><th>Cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td><code>Expected all tensors to be on the same device<\/code><\/td><td>Data on CPU, weights on GPU, or the reverse<\/td><td>Call <code>.to(device)<\/code> on every input, target and parameter<\/td><\/tr><tr><td><code>can&#039;t convert cuda:0 device type tensor to numpy<\/code><\/td><td>Calling <code>.numpy()<\/code> on a GPU tensor<\/td><td>Use <code>.detach().cpu().numpy()<\/code><\/td><\/tr><tr><td><code>Can&#039;t call numpy() on Tensor that requires grad<\/code><\/td><td>The tensor is still part of the autograd graph<\/td><td>Call <code>.detach()<\/code> first, or compute it inside <code>torch.no_grad()<\/code><\/td><\/tr><tr><td><code>AttributeError: &#039;NoneType&#039; object has no attribute &#039;zero_&#039;<\/code><\/td><td><code>.grad<\/code> is <code>None<\/code> because the parameter is a non-leaf tensor created by <code>.to()<\/code><\/td><td>Create it with <code>device=<\/code> or call <code>.requires_grad_()<\/code> after moving it<\/td><\/tr><tr><td><code>Torch not compiled with CUDA enabled<\/code><\/td><td>CPU-only PyTorch build<\/td><td>Install a CUDA build that matches your driver<\/td><\/tr><tr><td><code>CUDA out of memory<\/code><\/td><td>Batch or model is too large, or tensors are kept alive across steps<\/td><td>Use smaller batches, store <code>loss.item()<\/code> instead of <code>loss<\/code>, and delete unused references<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Best practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Define <code>device<\/code> once at the top of the script and pass it everywhere. Avoid hard-coding <code>.cuda()<\/code>, so the code still runs on machines without a GPU.<\/li>\n\n\n<li>For real models, use <code>nn.Linear<\/code> and an optimizer from <code>torch.optim<\/code> instead of updating weights by hand. <code>optimizer.zero_grad()<\/code> and <code>optimizer.step()<\/code> replace the manual block.<\/li>\n\n\n<li>Set <code>torch.manual_seed<\/code> for reproducible starting weights. Exact results can still differ slightly between CPU and GPU.<\/li>\n\n\n<li>Wrap evaluation in <code>torch.no_grad()<\/code> or <code>torch.inference_mode()<\/code> to save memory and time.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> A model this small trains faster on the CPU, because the cost of launching GPU kernels and copying data is larger than the work itself. The GPU version is for learning the device rules, not for speed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">How do I check if PyTorch can use my GPU?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run <code>torch.cuda.is_available()<\/code>. If it returns False, check that <code>torch.version.cuda<\/code> is not <code>None<\/code> (a CPU-only build), that the NVIDIA driver is installed, and that <code>nvidia-smi<\/code> lists the GPU.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why is w.grad None after I moved my weight to CUDA?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Calling <code>.to(&#039;cuda&#039;)<\/code> on a tensor that has <code>requires_grad=True<\/code> returns a new non-leaf tensor. PyTorch only fills <code>.grad<\/code> for leaf tensors. Create the tensor with <code>device=&#039;cuda&#039;, requires_grad=True<\/code>, or call <code>.requires_grad_()<\/code> after moving it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between .cuda() and .to(device)?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Both copy a tensor to a GPU. <code>.to(device)<\/code> also accepts a CPU device, so the same code runs on machines without a GPU, which makes it the safer choice.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why does nvidia-smi show more memory than my tensors use?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PyTorch&#039;s caching allocator keeps freed blocks reserved so it can reuse them. <code>torch.cuda.memory_allocated()<\/code> shows the memory your tensors actually use, and <code>torch.cuda.memory_reserved()<\/code> shows the cached total.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why is my GPU timing measurement wrong?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">CUDA operations run asynchronously, so the Python call can return before the GPU has finished. Call <code>torch.cuda.synchronize()<\/code> before starting and before stopping the timer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/artificial-intelligence\/machine-learning\/\">More Machine Learning tutorials<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/staff-mlops-engineer-role-blueprint-responsibilities-skills-kpis-and-career-path\/\">Staff MLOps Engineer: Role Blueprint, Responsibilities, Skills, KPIs, and Career Path<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/lead-machine-learning-engineer-role-blueprint-responsibilities-skills-kpis-and-career-path\/\">Lead Machine Learning Engineer: Role Blueprint, Responsibilities, Skills, KPIs, and Career Path<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This page covers a PyTorch lab notebook that fits a linear regression model with autograd and manual gradient descent. The title mentions CUDA, but the notebook above&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[6512],"tags":[7364],"class_list":["post-47574","post","type-post","status-publish","format-standard","hentry","category-machine-learning","tag-pytorch"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/47574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=47574"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/47574\/revisions"}],"predecessor-version":[{"id":80171,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/47574\/revisions\/80171"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=47574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=47574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=47574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}