{"record":{"id":"341342ce76c401fa","repo":"rohitg00/ai-engineering-from-scratch","slug":"max-context-length-must-be-1-got-max-context","errorCode":null,"errorMessage":"max_context_length must be >= 1, got {max_context_length}","messagePattern":"max_context_length must be >= 1, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/32-token-positional-embeddings/code/main.py","lineNumber":65,"sourceCode":"        if ids.dtype != torch.long:\n            raise TypeError(f\"ids must be long tensor, got {ids.dtype}\")\n        if ids.dim() != 2:\n            raise ValueError(f\"ids must be (B, T), got shape {tuple(ids.shape)}\")\n        return self.embedding(ids)\n\n\nclass LearnedPositionalEmbedding(nn.Module):\n    \"\"\"Position-id to vector lookup with learned parameters.\"\"\"\n\n    def __init__(\n        self,\n        max_context_length: int,\n        d_model: int,\n        init_std: float = DEFAULT_INIT_STD,\n    ) -> None:\n        super().__init__()\n        if max_context_length < 1:\n            raise ValueError(f\"max_context_length must be >= 1, got {max_context_length}\")\n        if d_model < 1:\n            raise ValueError(f\"d_model must be >= 1, got {d_model}\")\n        self.max_context_length = max_context_length\n        self.d_model = d_model\n        self.embedding = nn.Embedding(max_context_length, d_model)\n        _init_normal(self.embedding.weight, std=init_std)\n\n    def forward(self, seq_len: int) -> torch.Tensor:\n        if seq_len < 1:\n            raise ValueError(f\"seq_len must be >= 1, got {seq_len}\")\n        if seq_len > self.max_context_length:\n            raise ValueError(\n                f\"seq_len {seq_len} exceeds max_context_length {self.max_context_length}\"\n            )\n        positions = torch.arange(seq_len, device=self.embedding.weight.device)\n        return self.embedding(positions)\n\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/32-token-positional-embeddings/code/main.py#L47-L83","documentation":"Error \"max_context_length must be >= 1, got {max_context_length}\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/19-capstone-projects/32-token-positional-embeddings/code/main.py:65 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}