source context
D722ad53 D442 458e B561 Cab7e12fcbbf
ctx:claims/beam/d722ad53-d442-458e-b561-cab7e12fcbbfSource document
full textbeam-chunk
text/plain1 KB
doc:beam/d722ad53-d442-458e-b561-cab7e12fcbbfoptimizer = optim.Adam(model.parameters(), lr=0.001) # Using Adam optimizer scheduler = ReduceLROnPlateau(optimizer, mode='min', factor=0.1, patience=5, verbose=True) scaler = GradScaler() try: for epoch in range(100): running_loss = 0.0 for batch_idx, batch in enumerate(data_loader): inputs = batch['query'].float().to(device) labels = batch['label'].long().to(device) optimizer.zero_grad() with autocast(): outputs = model(inputs) loss = criterion(outputs, labels) scaler.scale(loss).backward() scaler.step(optimizer) scaler.update() running_loss += loss.item() # Log the processing log_entry = { 'timestamp': logging.LogRecord.created, 'level': 'INFO', 'epoch': epoch, 'batch_idx': batch_idx, 'batch_size': len(inputs), 'loss': loss.item(), 'learning_rate': optimizer.param_groups[0]['lr'] } log_json = json.dumps(log_entry) logging.info(log_json)
Facts in this context
Grouped by subject. Each subject links to its full article.
Log Entry10 factsex:log-entry
| containsLearningRate | Current Learning Rate |
| hasKey | Level Key |
| hasKey | Timestamp Key |
| hasKey | Batch Size Key |
| hasKey | Epoch Key |
| hasKey | Learning Rate Key |
| hasKey | Loss Key |
| hasKey | Batch Idx Key |
| rdf:type | Dictionary |
| rdf:type | Python Dictionary |
Scheduler9 factsex:scheduler
| adjusts | Adam Optimizer |
| adjustsParameter | Learning Rate |
| attachedTo | Adam Optimizer |
| factor | 0.1 |
| monitors | Validation Loss |
| monitorsMetric | Validation Loss |
| patience | 5 |
| rdf:type | Learning Rate Scheduler |
| reducesLearningRateWhen | Plateau Detected |
Training Sequence9 factsex:training-sequence
| rdf:type | Operational Sequence |
| step1 | Optimizer Zero Gradients |
| step2 | Forward Pass |
| step3 | Loss Calculation |
| step4 | Backward Pass |
| step5 | Optimizer Step |
| step6 | Scaler Update |
| step7 | Loss Tracking |
| step8 | Logging Call |
Reduce Lr on Plateau8 factsex:reduce-lr-on-plateau
| configuredOn | Adam Optimizer |
| factor | 0.1 |
| isInstance | Reduce Lr on Plateau |
| mode | Min Mode |
| patience | 5 |
| rdfs:label | Reduce Learning Rate On Plateau |
| rdf:type | Learning Rate Scheduler |
| verbose | true |
Adam Optimizer6 factsex:adam-optimizer
| adjustedBy | Scheduler |
| configuredOn | Model Parameters |
| learningRate | 0.001 |
| rdfs:label | Adam Optimizer |
| rdf:type | Optimizer |
| usesAlgorithm | Adam |
Batch Loop6 factsex:batch-loop
| iterates | Data Loader |
| nestedIn | Epoch Loop |
| provides | Batch Variable |
| provides | Batch Index Variable |
| rdf:type | For Loop |
| variableName | Batch |
Backward Pass5 factsex:backward-pass
| computesGradientsFor | Model Parameters |
| dependsOn | Loss Computation |
| rdf:type | Backpropagation |
| requires | Grad Scaler |
| scaledBy | Grad Scaler |
Logging Entry5 factsex:logging-entry
| containsBatchIndex | Batch Index |
| containsEpoch | Epoch |
| containsLevel | Info Level |
| containsTimestamp | Timestamp |
| rdf:type | Log Entry |
Optimizer Step5 factsex:optimizer-step
| dependsOn | Backward Pass |
| executedBy | Adam Optimizer |
| performedAfter | Backward Pass |
| rdf:type | Optimizer Step |
| requires | Grad Scaler |
Training Code5 factsex:training-code
| implementsPattern | Standard Pytorch Training Loop |
| rdf:type | Py Torch Training Script |
| usesAutocast | Mixed Precision Context |
| usesMixedPrecision | true |
| usesTryBlock | Error Handling |
Batch Processing4 factsex:batch-processing
| extractsLabel | Label Input |
| extractsQuery | Query Input |
| iteratesOver | Data Loader |
| rdf:type | Batch Processing |
Epoch Loop4 factsex:epoch-loop
| contains | Batch Loop |
| initializes | Running Loss |
| rdf:type | For Loop |
| variableName | Epoch |
Logging Call4 factsex:logging-call
| occursAfter | Loss Tracking |
| outputs | Json String |
| rdf:type | Logging Function Call |
| serializes | Log Entry |
Loss Calculation4 factsex:loss-calculation
| computedOn | Labels |
| computedOn | Outputs |
| rdf:type | Loss Computation |
| usesCriterion | Criterion |
Running Loss4 factsex:running-loss
| accumulatesAcross | Batches |
| initializedTo | 0 |
| rdf:type | Accumulator |
| resetEachEpoch | Epoch Loop |
Scaler Update4 factsex:scaler-update
| dependsOn | Optimizer Step |
| executedBy | Grad Scaler |
| rdf:type | Scaler Update |
| requires | Grad Scaler |
Training Loop4 factsex:training-loop
| containsBatchProcessing | Batch Processing |
| enclosedBy | Try Block |
| numberOfEpochs | 100 |
| rdf:type | Training Loop |
Autocast3 factsex:autocast
| encloses | Forward Pass |
| purpose | Mixed Precision Acceleration |
| rdf:type | Context Manager |
Batch3 factsex:batch
| containsField | Label Field |
| containsField | Query Field |
| derivedFrom | Enumerate |
Comment3 factsex:comment
| rdf:type | Developer Intent |
| statesPurpose | Adam Optimizer |
| statesPurpose | Logging |
Device3 factsex:device
| rdf:type | Compute Device |
| targetFor | Inputs |
| targetFor | Labels |
Device Placement3 factsex:device-placement
| appliedTo | Inputs |
| appliedTo | Labels |
| rdf:type | Tensor Device Transfer |
Forward Pass3 factsex:forward-pass
| occursWithin | Autocast Context |
| rdf:type | Model Forward |
| requires | Autocast Context |
Grad Scaler3 factsex:grad-scaler
| isInstance | Grad Scaler |
| rdfs:label | Gradient Scaler |
| rdf:type | Gradient Scaler |
Labels3 factsex:labels
| rdf:type | Tensor |
| type | Long Tensor |
| usedIn | Loss Calculation |
Loss Tracking3 factsex:loss-tracking
| accumulates | Running Loss |
| dependsOn | Scaler Update |
| rdf:type | Loss Accumulation |
Model3 factsex:model
| producesOutput | Outputs |
| rdf:type | Neural Network Model |
| receivesInput | Inputs |
Autocast Context2 factsex:autocast-context
| enables | Mixed Precision Training |
| rdf:type | Context Manager |
Batch Idx2 factsex:batch_idx
| derivedFrom | Enumerate |
| rdf:type | Iterator Index |
Comment 12 factsex:comment-1
| rdf:type | Code Comment |
| text | Using Adam optimizer |
Comment 22 factsex:comment-2
| rdf:type | Code Comment |
| text | Log the processing |
Enumerate2 factsex:enumerate
| rdf:type | Python Function |
| returns | Index Value Pairs |
Inputs2 factsex:inputs
| rdf:type | Tensor |
| type | Float Tensor |
Json.dumps2 factsex:json.dumps
| converts | Dictionary to Json |
| rdf:type | Serialization Function |
Label Input2 factsex:label-input
| convertedTo | Long Tensor |
| movedToDevice | Device |
Logging.log Record.created2 factsex:logging.LogRecord.created
| generates | Timestamp |
| rdf:type | Timestamp Generator |
Loss2 factsex:loss
| rdf:type | Tensor |
| scaledBy | Grad Scaler |
Loss Item2 factsex:loss-item
| extracts | Scalar Value |
| rdf:type | Tensor Method |
Optimizer.param Groups2 factsex:optimizer.param_groups
| contains | Learning Rate Parameter |
| rdf:type | Parameter Group |
Optimizer Zero Gradients2 factsex:optimizer-zero-gradients
| executedBefore | Forward Pass |
| rdf:type | Gradient Reset |
Outputs2 factsex:outputs
| producedBy | Model |
| usedIn | Loss Calculation |
Query Input2 factsex:query-input
| convertedTo | Float Tensor |
| movedToDevice | Device |
Try Block2 factsex:try-block
| encloses | Training Loop |
| provides | Error Protection |
Batch Index Variable1 factex:batch-index-variable
| generatedBy | Enumerate |
Batch['label']1 factex:batch['label']
| rdf:type | Batch Field |
Batch['query']1 factex:batch['query']
| rdf:type | Batch Field |
Data Loader1 factex:data-loader
| iteratedBy | Batch Loop |
Epoch Variable1 factex:epoch-variable
| range | 0 to 99 |
Float Conversion1 factex:float-conversion
| rdf:type | Type Conversion |
Label Field1 factex:label-field
| extractedFrom | Batch |
Len Function1 factex:len-function
| computes | Batch Size |
Len(inputs)1 factex:len(inputs)
| rdf:type | Length Function |
Logging1 factex:logging
| dependsOn | Loss Tracking |
Log Serialization1 factex:log-serialization
| rdf:type | Json Serialization |
Long Conversion1 factex:long-conversion
| rdf:type | Type Conversion |
Loss Computation1 factex:loss-computation
| dependsOn | Forward Pass |
Loss.item1 factex:loss.item
| converts | Tensor to Scalar |
Optimizer1 factex:optimizer
| steppedBy | Grad Scaler |
Optimizer.zero Grad1 factex:optimizer.zero_grad
| purpose | Gradient Clearing |
Query Field1 factex:query-field
| extractedFrom | Batch |
Range1 factex:range
| rdf:type | Python Function |
Running Loss1 factex:running_loss
| scope | Epoch Loop |
Running Loss Update1 factex:running-loss-update
| rdf:type | Augmented Assignment |