classConvLayerConfig(BaseModel):"""Single 1D convolution specification. Parameters define one convolution block as ``Conv1d(in_channels, out_channels, kernel_size, stride, padding)``. """kernel_size:intstride:intpadding:intclassEncoderConfig(BaseModel):"""Encoder architecture and normalization settings."""hidden_size:int=256norm_mode:Literal["batchNorm","instanceNorm","ID","layerNorm"]="layerNorm"conv_layers:list[ConvLayerConfig]=Field(default_factory=lambda:[ConvLayerConfig(kernel_size=10,stride=5,padding=3),ConvLayerConfig(kernel_size=8,stride=4,padding=2),ConvLayerConfig(kernel_size=4,stride=2,padding=1),ConvLayerConfig(kernel_size=4,stride=2,padding=1),ConvLayerConfig(kernel_size=4,stride=2,padding=1),])classARConfig(BaseModel):"""Autoregressive model selection and parameters. Supports recurrent modes (GRU/LSTM/RNN), Transformer mode, and identity mode (``no_ar``). """mode:Literal["GRU","LSTM","RNN","transformer","no_ar"]="LSTM"hidden_size:int=256n_levels:int=1reverse:bool=FalseclassLossConfig(BaseModel):"""CPC/InfoNCE objective configuration."""n_predictions:int=12negative_sampling_ext:int=128temperature:float=0.07importmath
fromfunctoolsimportcached_propertyfromtypingimportCallable,Literalimporttorchimporttorch.nnasnnimporttorch.nn.functionalasFclassCPCEncoder(nn.Module):"""Convolutional encoder for time-series CPC. Input is expected as ``[B, C_in, T]`` and output as ``[B, H, T_enc]``, where ``H`` is ``size_hidden`` and ``T_enc`` depends on convolution specs. """def__init__(self,input_channels:int=1,size_hidden:int=256,conv_specs:list[tuple[int,int,int]]|None=None,):"""Build the encoder stack. :param input_channels: Number of input channels ``C_in``. :param size_hidden: Number of output channels for each convolution block. :param conv_specs: List of convolution settings as ``(kernel_size, stride, padding)``. If ``None``, a default 5-layer downsampling stack is used. """super().__init__()norm_factory:Callable[[int],nn.Module]# norm_factory = nn.BatchNorm1dnorm_factory=nn.Identityifconv_specsisNone:conv_specs=[(10,5,3),(8,4,2),(4,2,1),(4,2,1),(4,2,1),]blocks:list[nn.Module]=[]in_channels=input_channelsforkernel_size,stride,paddinginconv_specs:blocks.extend([nn.Conv1d(in_channels,size_hidden,kernel_size,stride=stride,padding=padding,),norm_factory(size_hidden),nn.ReLU(),])in_channels=size_hiddenself.network=nn.Sequential(*blocks)self.output_dim=size_hidden@cached_propertydefoutput_dimension(self)->int:"""Return the encoder feature dimension ``H``."""returnself.output_dimdefforward(self,x:torch.Tensor)->torch.Tensor:"""Encode raw sequence features. :param x: Input tensor with shape ``[B, C_in, T]``. :returns: Encoded tensor with shape ``[B, H, T_enc]``. """returnself.network(x)classCPCAR(nn.Module):"""Recurrent autoregressive context model for CPC. Operates on encoded sequences in ``[B, T, C]`` format and returns contextualized representations in ``[B, T, C_ctx]``. """def__init__(self,dim_encoded:int,dim_output:int,n_levels_gru:int=1,rnn_type:Literal["GRU","LSTM","RNN"]="LSTM",reverse:bool=False,):"""Initialize recurrent AR module. :param dim_encoded: Input feature size ``C`` from the encoder. :param dim_output: Hidden/context size ``C_ctx`` of the recurrent module. :param n_levels_gru: Number of recurrent layers. :param rnn_type: Recurrent cell type. :param reverse: If ``True``, run AR in reverse time and flip output back. """super().__init__()self.reverse=reversernn_cls={"LSTM":nn.LSTM,"RNN":nn.RNN,"GRU":nn.GRU}[rnn_type]self.rnn=rnn_cls(dim_encoded,dim_output,num_layers=n_levels_gru,batch_first=True)@cached_propertydefoutput_dimension(self)->int:"""Return context feature dimension ``C_ctx``."""returnself.rnn.hidden_sizedefforward(self,x:torch.Tensor)->torch.Tensor:"""Run recurrent AR on encoded sequence. :param x: Encoded tensor with shape ``[B, T, C]``. :returns: Context tensor with shape ``[B, T, C_ctx]``. """ifself.reverse:x=torch.flip(x,[1])try:self.rnn.flatten_parameters()exceptRuntimeError:passx,_=self.rnn(x)ifself.reverse:x=torch.flip(x,[1])returnxclassCPCModel(nn.Module):"""Compose encoder and autoregressive context model."""def__init__(self,encoder:nn.Module,ar:nn.Module):"""Initialize CPC model. :param encoder: Module mapping ``[B, C_in, T]`` to ``[B, C_enc, T_enc]``. :param ar: Module mapping ``[B, T_enc, C_enc]`` to context features ``[B, T_enc, C_ctx]``. """super().__init__()self.encoder=encoderself.ar=ardefforward(self,batch_data:torch.Tensor)->tuple[torch.Tensor,torch.Tensor]:"""Run encoder then AR network. :param batch_data: Input batch with shape ``[B, C_in, T]``. :returns: Tuple ``(context, encoded)`` where ``context`` has shape ``[B, T_enc, C_ctx]`` and ``encoded`` has shape ``[B, T_enc, C_enc]``. """encoded=self.encoder(batch_data).permute(0,2,1)context=self.ar(encoded)returncontext,encodedclassCPCCriterion(nn.Module):"""InfoNCE loss used by Contrastive Predictive Coding. For each prediction horizon ``k``, the criterion predicts future encoded vectors from context, then contrasts one positive against sampled negatives. """def__init__(self,dim_context:int,dim_encoded:int,n_predictions:int=12,n_negatives:int=128,temperature:float=0.07,):"""Initialize CPC criterion. :param dim_context: Context feature dimension ``C_ctx``. :param dim_encoded: Encoded target feature dimension ``C_enc``. :param n_predictions: Number of future steps to predict. :param n_negatives: Number of negative samples per query. :param temperature: Logit temperature scaling factor. """super().__init__()self.n_predictions=n_predictionsself.n_negatives=n_negativesself.temperature=temperatureself.predictors=nn.ModuleList([nn.Linear(dim_context,dim_encoded,bias=False)for_inrange(n_predictions)])def_sample_negatives(self,encoded_pool:torch.Tensor,n_queries:int)->torch.Tensor:"""Sample negative encoded vectors. :param encoded_pool: Flattened encoded with shape ``[B*T, C_enc]``. :param n_queries: Number of query vectors to match. :returns: Negative samples with shape ``[n_queries, n_negatives, C_enc]``. """idx=torch.randint(low=0,high=encoded_pool.size(0),size=(n_queries,self.n_negatives),device=encoded_pool.device,)returnencoded_pool[idx]defforward(self,context:torch.Tensor,encoded:torch.Tensor)->torch.Tensor:"""Compute averaged InfoNCE loss across valid prediction horizons. :param context: Context tensor with shape ``[B, T, C_ctx]``. :param encoded: Encoded tensor with shape ``[B, T, C_enc]``. :returns: Scalar loss tensor. :raises RuntimeError: If no prediction horizon is valid, usually because ``T`` is too short relative to ``n_predictions``. """_,seq_len,_=encoded.shapeencoded_pool=F.normalize(encoded.flatten(0,1),dim=-1)total_loss:torch.Tensor|None=Noneused_steps=0forkinrange(1,self.n_predictions+1):ifseq_len-k<=0:breakc_t=context[:,:seq_len-k,:]z_pos=encoded[:,k:,:]z_hat=self.predictors[k-1](c_t)z_hat=F.normalize(z_hat.flatten(0,1),dim=-1)z_pos=F.normalize(z_pos.flatten(0,1),dim=-1)n_queries=z_hat.size(0)pos_logits=torch.sum(z_hat*z_pos,dim=-1,keepdim=True)z_neg=self._sample_negatives(encoded_pool,n_queries)neg_logits=torch.einsum("nc,nkc->nk",z_hat,z_neg)logits=torch.cat([pos_logits,neg_logits],dim=1)/self.temperaturetargets=torch.zeros(n_queries,dtype=torch.long,device=logits.device)step_loss=F.cross_entropy(logits,targets)total_loss=step_lossiftotal_lossisNoneelsetotal_loss+step_lossused_steps+=1ifused_steps==0:raiseRuntimeError("CPCCriterion has no valid prediction steps: encoded sequence length is too short "f"(seq_len={seq_len}) for n_predictions={self.n_predictions}. ""Use fewer downsampling conv layers, smaller strides, or lower n_predictions.")iftotal_lossisNone:raiseRuntimeError("CPCCriterion failed to compute loss: total_loss is None after processing all prediction steps. ")returntotal_loss/used_steps
Model
classOptimizerConfig(BaseModel):"""Optimizer hyperparameters."""learning_rate:float=2e-4weight_decay:float=1e-6classTrainerConfig(BaseModel):"""Trainer runtime options, including epoch count and output path."""epochs:int=100output_dir:str="lightning_logs/ts_cpc"classRuntimeConfig(BaseModel):"""Execution environment settings such as seed and device."""seed:int=0accelerator:Literal["auto","cpu","gpu","mps"]="auto"devices:int=1classTrainConfig(BaseModel):"""Top-level configuration object for CPC training."""encoder:EncoderConfig=Field(default_factory=EncoderConfig)ar:ARConfig=Field(default_factory=ARConfig)loss:LossConfig=Field(default_factory=LossConfig)optimizer:OptimizerConfig=Field(default_factory=OptimizerConfig)trainer:TrainerConfig=Field(default_factory=TrainerConfig)runtime:RuntimeConfig=Field(default_factory=RuntimeConfig)@classmethoddeffrom_yaml(cls,path:Path)->"TrainConfig":"""Load a training configuration from YAML. :param path: Path to a YAML file containing any subset of ``TrainConfig`` fields. :returns: Parsed configuration with defaults applied to omitted fields. """withopen(path)asf:data=yaml.safe_load(f)returncls(**(dataor{}))
classCPCLightningModule(L.LightningModule):"""Lightning wrapper around CPC model and criterion. This module handles model construction, train/validation steps, and optimizer configuration. """def__init__(self,config:TrainConfig,input_channels:int):"""Initialize the Lightning module. :param config: Hierarchical training configuration. :param input_channels: Number of input channels in each sample ``x`` where ``x`` has shape ``[B, C_in, T]``. """super().__init__()self.config=configself.save_hyperparameters(config.model_dump())encoder=CPCEncoder(input_channels=input_channels,size_hidden=config.encoder.hidden_size,# norm_mode=config.encoder.norm_mode,conv_specs=[(l.kernel_size,l.stride,l.padding)forlinconfig.encoder.conv_layers],)ar=CPCAR(dim_encoded=config.encoder.hidden_size,dim_output=config.ar.hidden_size,n_levels_gru=config.ar.n_levels,rnn_type=config.ar.mode,reverse=config.ar.reverse,)self.model=CPCModel(encoder,ar)self.criterion=CPCCriterion(dim_context=ar.output_dimension,dim_encoded=encoder.output_dimension,n_predictions=config.loss.n_predictions,n_negatives=config.loss.negative_sampling_ext,temperature=config.loss.temperature,)def_shared_step(self,batch,split:str):"""Run one shared forward/loss step for train or validation. :param batch: Tuple ``(x, y)`` where ``x`` has shape ``[B, C_in, T]`` and ``y`` is the label tensor. :param split: Metric prefix, typically ``"train"`` or ``"val"``. :returns: Scalar CPC loss. """batch_x,_=batchbatch_x=batch_x.permute(0,2,1).float()context,encoded=self.model(batch_x)loss=self.criterion(context,encoded)self.log(f"{split}_loss",loss,on_step=False,on_epoch=True,prog_bar=True,batch_size=batch_x.size(0),)returnlossdeftraining_step(self,batch,batch_idx):"""Run one training step. :param batch: Mini-batch tuple ``(x, y)``. :param batch_idx: Batch index within the epoch. :returns: Scalar training loss. """returnself._shared_step(batch,"train")defvalidation_step(self,batch,batch_idx):"""Run one validation step. :param batch: Mini-batch tuple ``(x, y)``. :param batch_idx: Batch index within the validation epoch. """self._shared_step(batch,"val")defpredict_step(self,data,batch_idx:int=0)->tuple[torch.Tensor,torch.Tensor]:"""Run one prediction step. :param data: Mini-batch tuple ``(x, y)``. :param batch_idx: Batch index within the prediction epoch. :returns: Tuple of context and encoded tensors. """x=data.permute(0,2,1).float()context,encoded=self.model(x)returncontext,encodeddefconfigure_optimizers(self):"""Create optimizer for model and criterion parameters. :returns: Adam optimizer configured from ``config.optimizer``. """returntorch.optim.Adam(list(self.model.parameters())+list(self.criterion.parameters()),lr=self.config.optimizer.learning_rate,weight_decay=self.config.optimizer.weight_decay,)
L.seed_everything(config.runtime.seed,workers=True)os.makedirs(config.trainer.output_dir,exist_ok=True)lightning_module=CPCLightningModule(config=config,input_channels=1)trainer=L.Trainer(max_epochs=config.trainer.epochs,accelerator=config.runtime.accelerator,devices=config.runtime.devices,default_root_dir=config.trainer.output_dir,log_every_n_steps=5,precision="32-true",# Enforce float32 for MPS compatibility)trainer.fit(lightning_module,datamodule=pdm_1_step)
Output (18 lines)
Seed set to 137
GPU available: True (mps), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
Missing logger folder: lightning_logs/synth_cpc/lightning_logs
| Name | Type | Params
-------------------------------------------
0 | model | CPCModel | 119 K
1 | criterion | CPCCriterion | 15.0 K
-------------------------------------------
134 K Trainable params
0 Non-trainable params
134 K Total params
0.536 Total estimated model params size (MB)
/Users/leima/git/github/emptymalei/deep-learning/.venv/lib/python3.10/site-packages/lightning/pytorch/trainer/connectors/data_connector.py:441: The 'val_dataloader' does not have many workers which may be a bottleneck. Consider increasing the value of the `num_workers` argument` to `num_workers=9` in the `DataLoader` to improve performance.
/Users/leima/git/github/emptymalei/deep-learning/.venv/lib/python3.10/site-packages/lightning/pytorch/trainer/connectors/data_connector.py:441: The 'train_dataloader' does not have many workers which may be a bottleneck. Consider increasing the value of the `num_workers` argument` to `num_workers=9` in the `DataLoader` to improve performance.
`Trainer.fit` stopped: `max_epochs=400` reached.
px.scatter(df_context,x="pc_1",y="pc_2",color="label",title="PCA of CPC Context Representations",width=800,height=600,color_continuous_scale="Viridis",)
Interactive Plotly figure: enable JavaScript to view it.
px.scatter(df_context_tsne,x="tsne_1",y="tsne_2",color="label",title="t-SNE of CPC Context Representations",width=800,height=600,color_continuous_scale="Viridis",)
Interactive Plotly figure: enable JavaScript to view it.
px.scatter(df_encoded_pca,x="pc_1",y="pc_2",color="label",title="PCA of CPC Encoded Representations",width=800,height=600,color_continuous_scale="Viridis",)
Interactive Plotly figure: enable JavaScript to view it.
px.scatter(df_encoded_tsne,x="tsne_1",y="tsne_2",color="label",title="t-SNE of CPC Encoded Representations",width=800,height=600,color_continuous_scale="Viridis",)
Interactive Plotly figure: enable JavaScript to view it.
# Faceted comparison: raw vs context vs encoded for the same reduction method# Produces two figures:# 1) PCA with facet rows (raw/context/encoded)# 2) t-SNE with facet rows (raw/context/encoded)# Rebuild tensors if they are not already in memorymodule=trainer.modelifhasattr(trainer,"model")elselightning_modulemodule.eval()device=module.deviceall_raw,all_context,all_encoded,all_labels=[],[],[],[]withtorch.no_grad():forx,y_batchinpdm_1_step.train_dataloader():x=x.permute(0,2,1).float().to(device)context,encoded=module.model(x)all_raw.append(x.cpu())all_context.append(context.cpu())all_encoded.append(encoded.cpu())all_labels.append(y_batch[:,0,0].cpu())raw_all=torch.cat(all_raw,dim=0)# [N, C_in, T]context_all=torch.cat(all_context,dim=0)# [N, T_enc, C]encoded_all=torch.cat(all_encoded,dim=0)# [N, T_enc, C]y=torch.cat(all_labels,dim=0).numpy().astype(np.float32)# Choose one view per family for fair visual comparisonZ_by_family={"raw":raw_all.reshape(raw_all.shape[0],-1).numpy(),# flatten_all_channels"context":context_all.reshape(context_all.shape[0],-1).numpy(),# flatten_tokens# "encoded": encoded_all.reshape(encoded_all.shape[0], -1).numpy(),# flatten_tokens"encoded":encoded_all[:,1,:].reshape(encoded_all.shape[0],-1).numpy(),# flatten_tokens}family_order=["raw","context","encoded"]defreduce_family(Z,method="pca",random_state=0):ifmethod=="pca":returnmake_pipeline(StandardScaler(),PCA(n_components=2,random_state=random_state),).fit_transform(Z)ifmethod=="tsne":n=Z.shape[0]perp=max(5,min(30,(n-1)//3))returnTSNE(n_components=2,perplexity=perp,random_state=random_state,init="pca",).fit_transform(Z)raiseValueError(f"Unknown method: {method}")defbuild_facet_df(method):rows=[]forfaminfamily_order:Z2=reduce_family(Z_by_family[fam],method=method,random_state=0)df_f=pd.DataFrame({"dim1":Z2[:,0],"dim2":Z2[:,1],"label":y,"family":fam,})rows.append(df_f)returnpd.concat(rows,ignore_index=True)defplot_facet(dataframe,method,width=700,height=1100):df_plot=dataframe.copy()title=f"{method.upper()} comparison by family (facet rows)"fig=px.scatter(df_plot,x="dim1",y="dim2",color="label",facet_row="family",category_orders={"family":family_order},title=title,width=width,height=height,color_continuous_scale="Viridis",opacity=0.8,)fig.update_traces(marker=dict(size=5))fig.for_each_annotation(lambdaa:a.update(text=a.text.split("=")[-1]))fig.update_layout(legend_title_text="label")fig.update_xaxes(matches=None)fig.update_yaxes(matches=None)fig.show()# Show both methods with the same faceting layoutdf_plot_pca=build_facet_df("pca")plot_facet(df_plot_pca,"pca")df_plot_tsne=build_facet_df("tsne")plot_facet(df_plot_tsne,"tsne")
Interactive Plotly figure: enable JavaScript to view it.
Interactive Plotly figure: enable JavaScript to view it.
importnumpyasnpimportpandasaspd# Expect df_dr columns from your merge:# dim1_pca, dim2_pca, dim1_tsne, dim2_tsne, label, familyrequired={"dim1_pca","dim2_pca","label","family"}missing=required-set(df_dr.columns)ifmissing:raiseValueError(f"df_dr is missing required columns: {missing}")# Keep only families needed for this vectordf_tmp=df_dr[df_dr["family"].isin(["raw","encoded"])].copy()# Create per-sample index inside each family block so raw and encoded can be paireddf_tmp["idx"]=df_tmp.groupby("family").cumcount()# Split and rename PCA columnsraw_df=(df_tmp[df_tmp["family"]=="raw"][["idx","label","dim1_pca","dim2_pca"]].rename(columns={"dim1_pca":"raw_x","dim2_pca":"raw_y"}).reset_index(drop=True))enc_df=(df_tmp[df_tmp["family"]=="encoded"][["idx","label","dim1_pca","dim2_pca"]].rename(columns={"dim1_pca":"enc_x","dim2_pca":"enc_y","label":"label_enc"}).reset_index(drop=True))# Pair raw and encoded rows by idx (and optionally validate labels)df_vec=raw_df.merge(enc_df,on="idx",how="inner")# Optional sanity check: label consistencyifnot(df_vec["label"]==df_vec["label_enc"]).all():print("Warning: label mismatch found between raw and encoded pairing.")df_vec=df_vec.drop(columns=["label_enc"])# Vector components and normdf_vec["vec_x"]=df_vec["enc_x"]-df_vec["raw_x"]df_vec["vec_y"]=df_vec["enc_y"]-df_vec["raw_y"]df_vec["vec_norm"]=np.linalg.norm(df_vec[["vec_x","vec_y"]].to_numpy(),axis=1)df_vec.head()
Interactive Plotly figure: enable JavaScript to view it.
# Derive vec_x / vec_y from whichever df_vec is in scopevec_x=(df_vec["enc_x"]-df_vec["raw_x"]).valuesvec_y=(df_vec["enc_y"]-df_vec["raw_y"]).valuesV=np.stack([vec_x,vec_y],axis=1)# [N, 2]labels=df_vec["label"].values# 1) Mean displacement and residualsv_mean=V.mean(axis=0)residuals=V-v_meanresidual_norms=np.linalg.norm(residuals,axis=1)vector_norms=np.linalg.norm(V,axis=1)explained_by_mean=1-(residual_norms/(vector_norms+1e-9))print(f"Mean displacement vector: ({v_mean[0]:.3f}, {v_mean[1]:.3f})")print(f"Mean |v|: {vector_norms.mean():.3f} ± {vector_norms.std():.3f}")print(f"Mean |residual|: {residual_norms.mean():.3f} ± {residual_norms.std():.3f}")print(f"Fraction explained by global shift: {explained_by_mean.mean():.3f}")# 2) Angle relative to mean directionv_mean_unit=v_mean/(np.linalg.norm(v_mean)+1e-9)cos_sim=np.clip(V@v_mean_unit/(vector_norms+1e-9),-1,1)angles_deg=np.degrees(np.arccos(cos_sim))# 3) PCA of displacement vectorspca_v=PCA(n_components=2).fit(V)print(f"\nPCA of displacement vectors — variance explained: {pca_v.explained_variance_ratio_}")df_angle=pd.DataFrame({"angle_deg":angles_deg,"residual_norm":residual_norms,"vec_norm":vector_norms,"label":labels,})fig=px.histogram(df_angle,x="angle_deg",color="label",nbins=30,barmode="overlay",opacity=0.7,title="Distribution of displacement angle relative to mean vector (degrees)<br>""<sup>Near 0° = moves with the crowd; large angle = outlier movement</sup>",labels={"angle_deg":"Angle to mean displacement (°)"},width=850,height=450,)fig.show()fig2=px.scatter(df_angle,x="vec_norm",y="residual_norm",color="label",title="Vector norm vs residual norm after removing global shift<br>""<sup>Near x-axis = moved with global trend; high residual = distinctive movement</sup>",labels={"vec_norm":"|v|","residual_norm":"|v - v̄|"},width=800,height=500,opacity=0.8,)fig2.add_hline(y=0,line_dash="dot",line_color="gray")fig2.show()
Mean displacement vector: (-0.000, 0.000)
Mean |v|: 10.584 ± 1.882
Mean |residual|: 10.584 ± 1.882
Fraction explained by global shift: 0.000
PCA of displacement vectors — variance explained: [0.65481544 0.34518456]
Interactive Plotly figure: enable JavaScript to view it.
Interactive Plotly figure: enable JavaScript to view it.
GPU available: True (mps), used: True
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
| Name | Type | Params
---------------------------------------
0 | pre_net | Identity | 0
1 | net | Sequential | 8.6 K
2 | loss | MSELoss | 0
---------------------------------------
8.6 K Trainable params
0 Non-trainable params
8.6 K Total params
0.034 Total estimated model params size (MB)
/Users/leima/git/github/emptymalei/deep-learning/.venv/lib/python3.10/site-packages/lightning/pytorch/trainer/connectors/data_connector.py:441: The 'val_dataloader' does not have many workers which may be a bottleneck. Consider increasing the value of the `num_workers` argument` to `num_workers=9` in the `DataLoader` to improve performance.
/Users/leima/git/github/emptymalei/deep-learning/.venv/lib/python3.10/site-packages/torch/nn/modules/loss.py:608: UserWarning:
Using a target size (torch.Size([25])) that is different to the input size (torch.Size([25, 1, 1])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
/Users/leima/git/github/emptymalei/deep-learning/.venv/lib/python3.10/site-packages/lightning/pytorch/trainer/connectors/data_connector.py:441: The 'train_dataloader' does not have many workers which may be a bottleneck. Consider increasing the value of the `num_workers` argument` to `num_workers=9` in the `DataLoader` to improve performance.
/Users/leima/git/github/emptymalei/deep-learning/.venv/lib/python3.10/site-packages/torch/nn/modules/loss.py:608: UserWarning:
Using a target size (torch.Size([32])) that is different to the input size (torch.Size([32, 1, 1])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
/Users/leima/git/github/emptymalei/deep-learning/.venv/lib/python3.10/site-packages/torch/nn/modules/loss.py:608: UserWarning:
Using a target size (torch.Size([2])) that is different to the input size (torch.Size([2, 1, 1])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
/Users/leima/git/github/emptymalei/deep-learning/.venv/lib/python3.10/site-packages/lightning/pytorch/trainer/connectors/data_connector.py:441: The 'predict_dataloader' does not have many workers which may be a bottleneck. Consider increasing the value of the `num_workers` argument` to `num_workers=9` in the `DataLoader` to improve performance.