Foundations
Sigmoid GELU Approximation
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Your task
Multiply each input entry x by sigmoid(1.702x). This named GELU approximation uses the same shape as x and a sharper sigmoid gain than SiLU.
Function signature
gelu_sigmoid_approximation(x: torch.Tensor) -> torch.TensorWorked example
Follow one activation
For x=[-1,0,1], multiply by sigmoid(1.702x), giving approximately [-0.154204,0,0.845796]. The positive-one result uses 1/(1+exp(-1.702)); changing 1.702 to 1 would change this exercise to SiLU.
Parameters
| Parameter | Shape and meaning |
|---|---|
xtorch.Tensor | Any shape, including empty axes.Values to activate independently at each position. |
Return
torch.Tensor · Exactly x.shape.
Return Transformed values.
Required behavior
f(x)=x\,\operatorname{sigmoid}(1.702x). This is neither exact GELU nor SiLU.- All axes, including empty axes, are preserved. Do not introduce learned parameters or a reduction.
- Use CPU float32/float64 tensors with one shared floating dtype/device. Accept noncontiguous input layouts and do not mutate supplied tensors.
- Use raw tensor operations, not a ready-made implementation of the requested primitive. Supplied parameters and random variates must not be reinitialized.
Why this matters
Enformer uses this inexpensive sigmoid approximation to GELU: small negative values are attenuated while large positive values pass through.
Starter code
You write the body of this function in the BioTorch workspace. Your code runs in an isolated PyTorch sandbox; Run checks the public examples and Submit grades the full test suite, including gradients.
import torch
def gelu_sigmoid_approximation(
x: torch.Tensor, # Any shape, including empty axes.
) -> torch.Tensor:
"""Return a tensor with shape x.shape."""
# Implement the operation. Inputs and test setup are supplied by BioTorch.
raise NotImplementedError("Implement gelu_sigmoid_approximation")
Ready to implement it?
3 progressive hints, a solution walkthrough, and grading that checks values, shapes and gradients are waiting in the workspace.
Free account with email, Google or GitHub. Your code runs in an isolated PyTorch sandbox.
Related exercises
Sources and further reading
A primitive exercise, not an end-to-end reproduction of the named models. No affiliation or endorsement is implied.